Я не эксперт по глобализации, на самом деле я не думаю, что когда-либо пробовал, но надеюсь, что это поможет.
Вот мой UserControl.xaml
<UserControl x:Class="Tab_Question.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="30">
<Grid>
<TextBlock Text="{Binding Path=CultureName, FallbackValue=bindingError}" />
</Grid>
Вот код, стоящий за UserControl.cs
public partial class UserControl1 : UserControl
{
public static DependencyProperty CultureStringProperty =
DependencyProperty.RegisterAttached("Culture", typeof(String), typeof(UserControl1));
public static DependencyProperty CultureNameProperty =
DependencyProperty.Register("CultureName", typeof(String), typeof(UserControl1));
public String CultureString
{
get
{
return (String)GetValue(UserControl1.CultureStringProperty);
}
set
{
if (CultureString != value)
{
SetValue(UserControl1.CultureStringProperty, value);
DoSomethingWithCulture();
}
}
}
private void DoSomethingWithCulture()
{
// Good to continue
CultureInfo newCulture = CultureInfo.GetCultureInfo(CultureString);
SetValue(UserControl1.CultureNameProperty, newCulture.Name);
}
public UserControl1()
{
InitializeComponent();
this.DataContext = this;
}
}
И, наконец, вот Window.xaml
<Window
x:Class="Tab_Question.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Tab_Question"
Title="Window1" Height="300" Width="300">
<StackPanel>
<local:UserControl1 CultureString="en-us" />
<local:UserControl1 CultureString="en-gb" />
</StackPanel>
Я постараюсь объяснить, что я сделал, надеюсь, это ответит на вопрос.
Я установил прикрепленный DependencyProperty в UserControl, который позволяет передавать строку CultureInfo в UserControl при обновлении строки. UserControl создает объект CultureInfo, который можно сохранить в переменной члена, и обновляет объект CultureName DependancyProperty, который TextBlock в UserControl привязывается к.
Я не уверен, почему заданный вами атрибут XmlLang не работает, но подозреваю, что он как-то связан с потоком пользовательского интерфейса, который может иметь только один язык.
Я знаю, что это не соответствует предоставленному вами примеру кода, но я надеюсь, что он предоставит вам стартовую площадку для изменения и адаптации.
Ben