本地化不在Silverlight框架中工作

时间:2013-03-11 06:06:00

标签: silverlight

在我的Silverlight应用程序中,我在该页面内有主页面,我有6个按钮(Page1,page2,Back,Forward,en-US,ja-JP)。

在MainPage框架中加载第1页的TextBox与属性捆绑在一起然后我加载第2页并将语言更改为Ja-Jp并单击Page1的选定后退按钮,但是在第1页文本框中未更改的语言是该代码。请帮助我来解决这个问题

        TextBox     Text="{Binding ElementName=page1,Path=MyLanguage.IetfLanguageTag, Mode=TwoWay}" 
   public XmlLanguage MyLanguage
    {
        get { return (XmlLanguage)GetValue(MyLanguageProperty); }
        set { SetValue(MyLanguageProperty, value); }
    }

    public static readonly DependencyProperty MyLanguageProperty =
        DependencyProperty.Register("MyLanguage", typeof(XmlLanguage), typeof(Page1), new PropertyMetadata(null, change));
    private static void change(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var update = d as Page1;
        update.languageChangeText.Text = ((System.Windows.Markup.XmlLanguage)(e.NewValue)).IetfLanguageTag.ToString();
    }

    public Page1()
    {
        InitializeComponent();
        Binding binding = new Binding();
        binding.Mode = BindingMode.TwoWay;
        binding.Source = this;
        //binding.RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.FindAncestor, AncestorType = typeof(ContentControl), AncestorLevel = 1 };
        binding.Path = new PropertyPath("Language");
        binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
        this.SetBinding(Page2.MyLanguageProperty, binding);
    }

1 个答案:

答案 0 :(得分:0)

看起来一切都是正确的,除了你的绑定路径

binding.Path = new PropertyPath(“Language”); 应为

binding.Path = new PropertyPath("MyLanguage");