Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it really important to use pack URIs in WPF apps?

Tags:

uri

wpf

Why should we use those, rather than ordinary ones?

what's the benefits of using this:

new Uri("pack://application:,,,/File.xaml");

over that:

new Uri("/File.xaml", UriKind.Relative);
like image 923
iLemming Avatar asked Aug 09 '10 16:08

iLemming


People also ask

What is Uri in WPF?

In Windows Presentation Foundation (WPF), uniform resource identifiers (URIs) are used to identify and load files in many ways, including the following: Specifying the user interface (UI) to show when an application first starts. Loading images.

What is pack application?

Application Pack means the object code software utility release(s) that are designed to work with the Software that may be, in Blackboard's sole discretion, issued in between Updates, designated by AP#, and/or later incorporated into Updates or Upgrades.

How do I add a resource to a project in WPF?

To add a Resource Dictionary into your WPF application, right click the WPF project > add a Resource Dictionary. Now apply the resource "myAnotherBackgroundColor" to button background and observe the changes.


1 Answers

The first one - you can use cross-assembly by adding a assembly-name after the three commas. So, you can create a shared library with common styles and other XAML-goodness that can be shared between several assemblies.

Syntax is like this:

pack://application:,,,/Common;component/CommonResources.xaml

where Common is the name of the assembly and everything after component is the path inside that assembly to the mapped resource. The latter can only be used inside the same assembly (and should be preferred).

I use it a lot for ResourceDictionaries residing in a common assembly above several module-type assemblies.

like image 149
Goblin Avatar answered Oct 19 '22 02:10

Goblin