开发者

How does WPF handle Windows Forms Resources functionality?

开发者 https://www.devze.com 2023-02-07 19:07 出处:网络
Does the introduction of WPF deprecates the Windows Forms Resources in any way? With Windows Forms Resources we could:

Does the introduction of WPF deprecates the Windows Forms Resources in any way? With Windows Forms Resources we could:

  • Provide internationalization for strings (i18n)
  • Embed images into the executable

Since I haven't fo开发者_C百科und an easy way for consuming those resources directly from the XAML, I suppose there is an alternative which works better with WPF. Is that so?


Embedded images work very easily in WPF. Just add the image to your Solution (with a type of Resource), and WPF can reference it from XAML, pulling it out of the resources directly. This is completely seamless.

Internationalization is a bit trickier, though. You can internationalize strings using resource files, just like in Windows Forms. However, strings within XAML are not handled the same way. There are two approaches to internationalization in WPF - both of which require a bit more effort than Windows Forms. However, there is a lot more flexibility and power in WPF internationalization.

First, you can use a markup extension to internationalize a string in WPF. This requires some custom plumbing to be written, but works more like the Windows Forms approach.

The more powerful approach is to actually load different XAML based on the region. This allows you to not only change your strings, but also adapt your UI layout - hence the extra power and flexibility (at the cost of more design time).

0

精彩评论

暂无评论...
验证码 换一张
取 消