Silverlight Path Resolution

First let me explain path resolution.  I have an image I want to use as my XAML button.  Easy enough I add an Image control to my Control Template for the button and set the source to the path of that image.  Path resolution is how the compiler determines where that image is.  I could hard code it to a directory on my hard drive, but that is never good because that path could change between environments or client machines.  So, most times we use relative paths.  Combinations of  ".." and slashes help us navigate the application structure to find the files.

Path resolution in XAML can be hard to understand.  It get's even more complicated once you add Silverlight to the mix.  Then on top of that when you are using User Controls from a Silverlight User Control Library things get down right nasty!  Then add in some shared Control Templates and things get darn near impossible.  That is the scenario I'm in.  I ran across this article which helped me get it working.  Check it out.

http://community.irritatedvowel.com/blogs/pete_browns_blog/archive/2008/03/09/Silverlight-2-Beta-1-Path-and-File-Resolution.aspx

One important thing to note is how you must mark the properties on the images.  Depending on how you are going to access the files you have to either set the Build Action property as "Content" or "Resource".  You might also need to set the Copy To Output Directory property to "Copy Always".

Another thing to note in my case is that if the Control Template is a shared\application level template, the images must reside in the application project, not the control library.  The path used in the shared Control Template is related to the application not the control library.

The most important thing is to pick a one way and stick to that throughout the application.

XAML Data Binding Slides and Demos

Last night I presented at the South Colorado .NET User Group.  The discussion started with XAML data binding basics and then went into some more advanced topics.  I basically covered how to bind to any back end data source I could think of including the ADO.NET Entity Framework.  I also covered some style and UI topics.  It was a fun discussion and I think my point regarding the power of data binding in XAML and WPF was made.  I have uploaded a zip file of the slides and demos.  The link is below:

http://www.htechinc.com/files/XAML%20Data%20Binding%20With%20WPF.zip

I also mentioned a cool add in for Visual Studio called XAML Power Toys developed by Karl Shifflett.  Here is the link to XAML Power Toys:

http://karlshifflett.wordpress.com/xaml-power-toys/

If you have any questions regarding either of these links please let me know.