WPF comes with a new URI Scheme which one can use to reference a file that is packaged as resource into the assembly. Rather than using DynamicResource, or specifying the absolute path for the Resource (which would eventually translate itself to relative reference always), the actual path can also be restored using pack:\\ URI Schema.
Pack Uri entails the Open Packaging Convension which determines organization and identification of Resources. Let us look into this in detail using few examples :
Here the application will find the file named ResourceFile.xaml directly to the Application Directory. Thus to refer to any file located in current assembly and which is in Root folder, you might use this.
If the file is located within a subfolder, to refer to it, you need to use Relative path from the root directory. Here you can see there is a subfolder named Subfolder where the ResourceFile.xaml is stored.
If you want to refer to the resource using the Referenced dll, you might use this. Remember the ReferencedAssembly refers to the name of the Assembly. Also remember if you place the ResourceFile.xaml in your root directory of referencedAssembly you should specify the path using component/ResourceFile.xaml. Therefore you can see, every file that is referenced through the ReferencedAssembly should always be relative to component folder. So for instance
Similar to one specified above, if the resource is placed within a subfolder within the assembly, you need to again reference that relative to component folder.
Finally if say your file is located to an assembly to which the current assembly is referenced to, you might use siteoforigin in this case to refer to a file located to the parent of this assembly.
Here you must remember that using this type of urls will make the dll tightly coupled with one another. Thus it will expect the dll which reference it to contain a file inside subfolder of its Resource tree structure.
It is really new to everybody to use these type of urls in WPF applications. Even I am also surprised to see such a new addition. But now I an using it, and also it works great to me. Try out them yourself, I hope you will find them interesting .
Thanks for reading.
For further reference you can read this Article
Read Disclaimer Notice
Author's new book
Abhishek authored one of the best selling book of .NET. It covers ASP.NET, WPF, Windows 8, Threading, Memory Management, Internals, Visual Studio, HTML5, JQuery and many more...
Grab it now !!!
Grab it now !!!