代码之家  ›  专栏  ›  技术社区  ›  Vijay

如何在源对象更改时动态更新绑定?

  •  0
  • Vijay  · 技术社区  · 15 年前

    我有什么?

    我有 Frame 在XAML中,(绑定工作正常)。

    <Frame Name="frmMainContent"
                 DataContext="MyPageInformation"
                 Source="{Binding ElementName=thisPage, Path=MyPageInformation.UserControlPath}"
                 NavigationUIVisibility="Hidden"></Frame>
    

    在代码后面我有一个 DependencyProperty 我的班级, PageInformation

    public static DependencyProperty PageInformationProperty = DependencyProperty.Register("MyPageInformation", typeof(PageInformation), typeof(Administration));
    
        public PageInformation MyPageInformation
        {
            get { retur n (PageInformation)GetValue(PageInformationProperty); }
            set{ SetValue(PageInformationProperty, value); }
        }
    

    我想要什么?

    这个 框架 每当值为 MyPageInformation 变化。

    有人能告诉我如何做到这一点吗?

    事先谢谢!

    2 回复  |  直到 13 年前
        1
  •  1
  •   Trainee4Life    15 年前

    您不必仅为此绑定将pageInformation属性设置为依赖属性。在代码隐藏中实现InotifyPropertiesChanged。

    另外,由于您实际上绑定到“UserControlPath”,请确保此属性实际发送更改通知。

        2
  •  0
  •   Trainee4Life    15 年前

    首先,我要告诉您的是,所有绑定错误都出现在输出窗口上。所以你需要看看它并找出你是否有任何错误。

    接下来……对于要自动更新的绑定,您要么需要使其“绑定”到的属性成为依赖属性,要么为其他类实现INotifyPropertyChanged。

    请确保您确切绑定到的属性是这些情况中的任何一种。