In WPF if you are loading images or resources from code, the syntax to do so is less than obvious. Main confusion is with the format that is passed to Uri class constructor and I have gotten it wrong more time than I can count so I thought it would be good thing to write this up so I can refer to it later, and you might find it helpful as well.

The image that is loaded this way is included in the project with Build Action set to Resource (default action). You can verify build action if you right-click the image in your VS.NET Solution Explorer and choose Properties. See what Build Action property is set to, it should be Resource.

So here is code that creates new Image and sets its source, the image in this sample is located in images folder in your project:

Image image = new Image();
image.Source = new BitmapImage(new Uri(@"pack://application:,,,/images/Globe.png",
image.Stretch = Stretch.None;

Notice the critical line and syntax for Uri constructor. This will load the image or resource from the same assembly. What to do if you want to load from different assembly? Then use this syntax:

image.Source = new BitmapImage(
          new Uri(@"pack://application:,,,/MyReferencedAssembly/images/Globe.png",

Where MyReferencedAssembly is the name of assembly you want to load resource from.

For more information you ever wanted on Pack URI’s check this article in MSDN.

Tagged with:

Hello Good People,

We just released DotNetBar for Windows Forms 9.2 with all new Gauge Control which extends our Instrumentation control offering.

The new DotNetBar Gauge control is highly customizable and interactive instrumentation control. You can create linear and circular gauges, add multiple bars and scales, nest gauges and more. All this is included in one single control with consistent programming interface and complete customization of its appearance.

Here is screen-shot from sample application that we included with this latest release:

Gauge Control has following major features:

  • Circular and Linear gauges
  • Multiple gauge needles and bars
  • Nested gauges
  • Multiple gauge scales
  • Custom gauge scales
  • Custom scale tick-marks
  • Extensive background and border styling
  • Custom rendering support

DotNetBar Gauge control also allows for completely custom rendering that you can easily plug-in to render something like this:

If you need help getting started with the Gauge Control read Gauge Control Quick Start Guide in our Knowledge Base and check-out the sample project included with controls.

There are over 50 new features and enhancements in this release. Here are detailed Release Notes. Notably there are following major new additions in 9.2 release:

  • AdvTree control now can stretch specified column to fill the width of the control so you can use all horizontal space available.
  • AdvPropertyGrid control now allows you to plug-in your own custom property value editors and use pre-built ones. We included Date/Time, Integer, Double and Option-Button editors. These editors are used to directly edit property values. We also provide new IPropertyValueEditor interface that you can use to create your own editors. The property grid sample project has been updated to show how all this works and it includes sample of custom property valued editor that implements IPropertyValueEditor interface.
  • You can now set whether close button is visible for each dock window using new DockContainerItem.CanClose property.
  • Color-picker in Office 2010 style has been updated to show Office 2010 style colors.

If you have current DotNetBar license download latest release on Customer Only web site. Fully functional trial version is also available. We are working on even more major new exciting features that I can’t wait to share with you….  After they are fully baked that is :-) Let me know what else you need from DotNetBar.

PS. Don’t forget to give our Silverlight controls a try if you need great looking Silverlight controls. Our DotNetBar for WPF is also awaiting new major release with some long awaited controls you asked for. New Year is starting with a bang! 🙂

Thank you for using DotNetBar!


Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

© 2009 Denis Basaric: DevComponents Blog