Bind Title for the ChildWindow to a localized resource using MVVM and Extension

I need to ensure my Silverlight application is localizable, so I am binding to a localizable resource file in the project. The issue is, how do I bind to the Title property? It crashed when trying to bind to a local resource since it hasn’t loaded the resources at this point. Even though the designer shows it working, the application doesn’t like it.

So I originally over engineered this by doing a custom extension. After too much coding, and getting it to work by the way, it dawned on me….Much easier way. Just set the childwindow title property after the resources tag…Argghhhh…….

Easy title binding

<controls:ChildWindow.Resources>
 <res:LocalizedStrings xmlns:local ="clr-namespace:PwC.AuraOnline.Modules.DeployEngagement" x:Key="LocalizedStrings" />
 <infrastructure:BooleanToVisibilityConverter x:Key="boolVisibilityConverter"/>
 </controls:ChildWindow.Resources>
 <controls:ChildWindow.Title>
 <TextBlock Text="{Binding  ClientSearchResources.WindowTitle,Source={StaticResource LocalizedStrings}}"></TextBlock>
 </controls:ChildWindow.Title>

I hope this helps someone out.

Happy Coding!

0 Replies to “Bind Title for the ChildWindow to a localized resource using MVVM and Extension”

  1. Thanks for posting this. Thank you Brian for sharing and saving me the time you spent figuring this out. Nice!

  2. Setting the Title had all ways bothered me as I was doing it in the code behind on loaded. Now I can MVVM it. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *