70-511 Exam Prep: Pack URIs in WPF

Another blog that won’t get many hits, sigh, hope it isn’t as bad as security blogs.  Of course it won’t get as many hits as the Kinect Hack blog.  Anyway…This is a brain dump from reading the entry at: https://msdn.microsoft.com/en-us/library/aa970069.aspx

I put it into the UI objective for the WPF exam 70-511 because it would be a great way to mess with your brain on the exam.  Which the only people taking the exam are Kenny Spade (see his excellent blog at https://blogs.msdn.com/kennyspade ), you and me.  Good luck, I am taking my first run at the exam next week, I have no hope that I am completely prepared, but I figure if my time is worth $30/hour (study time) and I manage to pass the exam, then I won’t study anymore.  If I don’t pass, no harm, I can take it again and I have a better idea of what is on the exam.  Kenny is being smart and taking the class, which if I fail the exam I will plan on taking as well.

Let’s say there is a question like:

Using the .NET Framework 4 to develop a WPF application that includes the an image file, Space_Aliens.png stored as a resource within the ImageResources assembly, that is 1600 by 1200 pixels. The UFO webazine you are working for at the moment needs to display the image at 1200 by 800 pixels without any size distortion.

What do you use?

  1. <Image Height="900" Width="700" Stretch="Fill"   Source="pack://application:,,,/Resources;component/Space_Alien..jpg" />
  2. <Image Height="900" Width="700" Stretch="Uniform” Source="/Space_Alien..jpg" />
  3. <Image Height="900" Width="700" Stretch="UniformToFill"  Source="/Space_Alien..jpg" />
  4. <Image Height="900" Width="700" Source="pack://application:,,,/Resources;component/Space_Alien.jpg" />

Ha-ha, none of them, the size and extension is incorrect!  Let’s try that again:

  1. <Image Height="1200" Width="800" Stretch="Fill"   Source="pack://application:,,,/Resources;component/Space_Alien..png" />
  2. <Image Height="1200" Width="800" Stretch="Uniform"   Source="/Space_Alien..png" />
  3. <Image Height="1200" Width="800" Stretch="UniformToFill"  Source="/Space_Alien..png" />
  4. <Image Height="1200" Width="800" Source="pack://application:,,,/Resources;component/Space_Alien.png" />

If I was taking the exam, I would have picked 2, and I would be WRONG.  It’s 4.  Darn-it!

Packages and parts are analogous to applications and files, where an application (package) can include one or more files (parts), including:

  • Resource files that are compiled into the local assembly.
  • Resource files that are compiled into a referenced assembly.
  • Resource files that are compiled into a referencing assembly.
  • Content files.
  • Site of origin files.

To access these types of files, WPF supports two authorities: application:/// and siteoforigin:///. 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. The scope of each authority is shown in the following figure.

Relationship among package, authority, and path

Packages and parts are analogous to applications and files, where an application (package) can include one or more files (parts), including:

  • Resource files that are compiled into the local assembly.

  • Resource files that are compiled into a referenced assembly.

  • Resource files that are compiled into a referencing assembly.

  • Content files.

  • Site of origin files.

To access these types of files, WPF supports two authorities: application:/// and siteoforigin:///. 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. The scope of each authority is shown in the following figure.

Pack URI diagram