How to fetch string from resource to assign in WPF Resource section in xaml

I was able to do it in a program with:

<TextBlock VerticalAlignment="Center" Margin="3"
           Text="{x:Static prop:Resources.OpenButton}"
           Visibility="{Binding Source={x:Static prop:Settings.Default}, Path=ShowButtonText, 
           Converter={StaticResource BoolToVis}}"></TextBlock>

I also had to include the .Properties namespace in my xaml, like so:

xmlns:prop="clr-namespace:MyProjectNamespace.Properties"

This allowed me to not only use the string resources I had defined for my project for globalization, but I was also able to bind (two way) to my application’s Settings. This let me very easily remember the window’s position, size, etc. As you can see, use Settings. for settings, and Resources. for resources.

As Steven mentioned, I think the “official” way or the “best” way is to stick x:Uid on everything that you want to globalize, but I didn’t and it worked with no problems. I think the x:Uid thing is mostly required if you are using automated tools or breaking the translation task up as you would in a large project. I just did all my own stuff manually in VS, so maybe it was ok.

Ben

Leave a Comment