Get values from *.resx files in XAML

前端 未结 7 2063
攒了一身酷
攒了一身酷 2020-11-30 23:24

Is it possible to add some value from resource file right into the XAML markup? Or for localization we always have to make something like this in *.cs file:

         


        
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 23:59

    I understand my reply is a bit late, but I thought its worth sharing:

    To use a string stored in the *.resx file without Static keyword:

    1. In App.Xaml file add a namespace for Properties xmlns:resource="clr-namespace:YourProject.Properties"
    2. In ApplicationResources(app.xaml file) Add a Resource for your *.resx file

    3. In your XAML file use the following Binding, let us take an example of Window Title

      Title="{Binding TitleString, Source={StaticResource ResourceKey=ApplicationStringResources}}"

      TitleString is the name of StringProperty in your *.resx file

    4. Last but not least, don't forget to change the resource file access modifier to Public.

提交回复
热议问题