DataGridTextColumn Column Header DynamicResource Binding Fail

Nov 5, 2009 at 2:35 PM

I am using the datagrid and gridtextcolumn for my application. I bind the column header with a string resource defined in resourceDictionary.

<dg:DataGridTextColumn Width="40" Header="{DynamicResource Header1}" Binding="{Binding Name}" />

But I find that the column header will not changed after reloading the resource from "Resource 1" to "Resource 2"

Resource 1.xaml

    <ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" .........>

            <sys:String x:Key="Header1">Name(English)</sys:String>

    </ResourceDictionary>

Resource 2.xaml

    <ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" .........>

            <sys:String x:Key="Header1">Name(Japanese)</sys:String>

    </ResourceDictionary>

I need this to support multi-language.

Can anyone help?

Thankyou~~

Nov 8, 2009 at 9:17 PM
Edited Nov 8, 2009 at 9:17 PM

For localization, you have to deal with project Resource.resx, Resource.jp.resx. (like WindowsForms )

In your project resources define string Header1

In code behind, you also have to declare property Header1 like this

 

//return string from resources.resx
public string Header1

{

get
	{

	return Properties.Resources.Header1;

	}

} 


 

 

In xaml

Header="{Binding RelativeSource={RelativeSource Self}, Path=Header1}"

 

 

When you changed CultureUI, it will change your string.