Home > WPF > URIs in Windows Presentation Foundation

URIs in Windows Presentation Foundation

It seems that understanding and using uniform resource identifiers (URI) is essential in WPF. After searching web and MSDN help I found following articles useful:

 

With a bit of simplification, I can describe the URI as a new method for identifying the relative or absolute location of a file.

The key element of the URI is the package scheme.  which represent the logical path of a content. It contains two parts Authority and Path.

pack://authority/path

WPF supports two authorities:

  • application:///
  • siteoforigin:///

 

MSDN: “The application:/// authority identifies application data files that are known at compile time, including resource and content files. The siteoforigin:/// authority identifies site of origin files.”

I found that Application authority is adequate in majority of cases including  accessing a file or a resource from the local or referenced assembly.

Important: to conform to RFC 2396, the “/” character must be replaced with the “,” character and other reserved characters must be escaped including “%” and “?”

Following examples shows pack URI for different scenarios:

Resource file – local assembly

“pack://application:,,,/ResourceFile.xaml”

 

Resource file in subfolder – local assembly

“pack://application:,,,/Subfolder/ResourceFile.xaml”

 

Resource file – referenced assembly

“pack://application:,,,/ReferencedAssembly;component/ResourceFile.xaml”

 

Resource file in subfolder of referenced assembly

“pack://application:,,,/ReferencedAssembly;component/Subfolder/ResourceFile.xaml”

 

Resource file in versioned referenced assembly

“pack://application:,,,/ReferencedAssembly;v1.0.0.0;component/ResourceFile.xaml”

 

Content file

“pack://application:,,,/ContentFile.xaml”

 

Content file in subfolder

“pack://application:,,,/Subfolder/ContentFile.xaml”

 

Site of origin file

“pack://siteoforigin:,,,/SOOFile.xaml”

 

Site of origin file in subfolder

“pack://siteoforigin:,,,/Subfolder/SOOFile.xaml”

Advertisements
Categories: WPF

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: