What is Uri Pack, and ":,,," in a BitmapImage?

KMC picture KMC · Mar 22, 2011 · Viewed 22.2k times · Source

What I add a Image.Source I have to type the following:

playIcon.Source = new BitmapImage(new Uri(@"pack://application:,,,/TempApplication2;component/Images/play.png"));

I'm moving from web development to WPF C# and I don't get why setting a Path has extra stuff in it, where in CSS I simply add a Path string.

Can someone explain why there is Uri, pack, and the ":,,,", Application2:component?

I'm new to WPF C#.

Answer

Code0987 picture Code0987 · Mar 22, 2011

The pack uri is used to identify & locate resources, files in application and remote. The pack uri in WPF uses 'pack://authority/path' format. And this is the line from MSDN which explains this format, 'The authority specifies the type of package that a part is contained by, while the path specifies the location of a part within a package'

WPF supports two authorities: application:/// and siteoforigin:///. The application:/// authority identifies resource files, content files. The siteoforigin:/// authority identifies site of origin files.

":///" is written ":,,," because the "/" character must be replaced with the "," character, and reserved characters such as "%" and "?" must be escaped and URI that points to a package and must conform to RFC 2396.

For more info please read "Pack URIs in WPF"

I'm also learning WPF. This is what i have understood about Pack Uri in WPF till now.