开发者

using resources in xaml according to localization

开发者 https://www.devze.com 2023-02-07 17:46 出处:网络
I like pretty much of the localization model in asp.mvc. You have the resx-fallback mechanism and with some html-helper methods you can easily reference your resources in your views.

I like pretty much of the localization model in asp.mvc. You have the resx-fallback mechanism and with some html-helper methods you can easily reference your resources in your views.

ie: <%: Html.Resource("ApplicationTitle") %>

I want to know if there is something similar in WPF. If you can use something like this on xaml:

<TextBlock Text="{Binding Source=Resources.ApplicationTitle}" />

Also how to tell your application which resource file to use (default, en, en-us).

Edit:

I found how to reference resources properties directly on XAML. You can have a Language.resx file on your soluti开发者_如何学Goon and reference it on App.xaml:

<SolutionName:Language x:Key="LocalizedStrings" />

Then just use something like this on XAML:

<TextBlock Text="{Binding Path=ApplicationTitle, Source={StaticResource LocalizedStrings}}" />

The only problem now is how to decide which resource to use: Language.resx or Language.en.resx


You could easily do something like this writing a custom:

  • attached property,
  • behavior or
  • markup extension
0

精彩评论

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