When you create a WPF application, the start-up window is by default one from the same project (by default called Window1.xaml).
1 2 3 4 5 6 7 8 |
< Application x:Class="WpfApplication1.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="Window1.xaml" > < Application.Resources > < /Application.Resources > < /Application > |
But what if you want to use a window from another project (class library)? The pack URI scheme, used by WPF, allows you to identify and load files from:
- the current assembly
- a referenced assembly
- a location relative to an assembly
- the site of origin for the application
The format of the pack URI is pack://authority/path. The authority identifies the type of package and the path the location of a part inside a package. There are two authorities supported by WPF:
- application:/// identifies application data files (known at compile time)
- siteoforigin:/// identifies site of origin files
To use resource files from a referenced assembly you need to use the application:/// authority, and the path must have the form AssemblyShortName[;Version][;PublicKey];component/Path. Version and PublicKey are optional.
Let’s say you want to use a XAML called SampleWindow.xaml from a referenced assembly called WpfDemoLib. The App.xaml file should look like this:
1 2 3 4 5 6 7 8 |
< Application x:Class="WpfApplication1.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="pack://application:,,,/WpfDemoLib;component/SampleWindow.xaml" > < Application.Resources > < /Application.Resources > < /Application > |
You can learn more about pack URIs in WPF from MSDN.
That’s save my day, Thanks for your work. May I know ?,what these three commas after “application/” in
pack://application:,,,/WpfDemoLib;component/SampleWindow.xaml”