0

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

在 MainPage 框架中加载第 1 页中的第 1 页 TextBox 与属性绑定然后我加载第 2 页并将语言更改为 Ja-Jp 并单击第 1 页的选定后退按钮但第 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);
    }
4

1 回答 1

0

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

binding.Path = new PropertyPath("语言"); 应该

binding.Path = new PropertyPath("MyLanguage");
于 2013-03-11T07:24:04.060 回答