Best practices for using resources in a WPF project

I know and use two methods of storing and accessing resources in the application area:

  • Properties \ Resources.resx
  • 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 resources best used in WPF and VB or C # encoder?

Thanks in advance,

Julian

+8
resources wpf
source share
1 answer

The "natural" way of referencing resources, such as images in a WPF project, is your second option. You can use a relative URI to point to an image, and WPF will lazily load it. You can reference resources in other assemblies using the package URI syntax .

Using Resources.resx will generate code properties that load resources when referenced. Resources can be strings, images, icons, or 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 to the type used by WPF.

There is some localization support using Resources.resx , and if you want to provide a multilingual application, you can save 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 simpler. For strings, the first option is probably simpler, but instead, you can stay in XAML and create a ResourceDictionary .

+6
source share

All Articles