9

I know and use two methods to store and access resources on application scope:

  1. Properties\Resources.resx
  2. create a folder and place for example images there, setting their build mode to Resource

What is the difference between the two methods in terms of performance and complexity, when should each be used and how are the resources best consumed in WPF and VB or C# code in each way?

Thanks in advance,

Julian

1 Answer 1

7

The "natural" way of referencing resources like images in a WPF project is your second option. You can use a relative URI to point to the image and WPF will lazy load it. You can reference resources in other assemblies using pack URI syntax.

Using Resources.resx will code-generate properties that loads resources when referenced. Resources can be strings, images, icons or a byte arrays. Using {x:Static} in XAML allows you to reference the static properties generated by the code-generator but often you will need a converter to convert the resource type into a type usable by WPF.

There is some support for localization using Resources.resx and if you want to provide a multi-lingual application you could store the translated strings in Resources.resx. However, WPF localization as described by Microsoft is not based on Resources.resx.

For images, the second option is much easier. For strings, the first option is probably easier but instead you could stay in XAML and create a ResourceDictionary.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.