MessageBox Button text localization issue

Jan 6, 2012 at 5:29 AM


I have set up a style trigger at App.xaml to change the button text of the message boxes.

<Style TargetType="{x:Type ex:MessageBox}">
		<DataTrigger Binding="{Binding Converter={c:LanguageConverter}}" Value="True">
			<Setter Property="OkButtonContent" Value="{lex:LocText AppName:Common:Text_Ok}" />

When ever the message box is shown, my LanguageConverter is getting called and it is set to return 'True' always. But the message box button text is not set at runtime. Only when I restart the application, the correct language is set on the items.  I am using WPF Localization Extension (lex:LocText) to bind text from the resource files, but that is working fine for other xaml pages and the text gets localized at runtime without any issues.

If you have any ideas on what I am doing wrong here or know any other way to get the job done, please let me know.

Thank you.

Jan 6, 2012 at 6:21 AM
Edited Jan 6, 2012 at 6:24 AM

Hi I found a work around for this issue:

Looks like I really do not need a style trigger here. The styles are evaluated every time when the message box is shown, not just once. Now I have the following xaml.


<Style TargetType="{x:Type ex:MessageBox}">
		<Setter Property="OkButtonContent" Value="{Binding OkButtonContent, Source={x:Static Application.Current}}" />                    


Then I have a public property called 'OkButtonContent' in App.xaml.cs which programatically returns the culture specific text. In my case it is the following:


public string OkButtonContent
	get { return ResourceHelper.GetLocalizedCommonText("Button_Ok_Text"); }

Whenever the is called, this property gets evaluated via the style binding and therefore the button text is set at runtime.

Jan 7, 2012 at 2:35 AM

Thank you for posting your solution.  It will definitely help others looking to accomplish the same task.