【问题标题】:Binding an Element to a Control Property (string)将元素绑定到控件属性(字符串)
【发布时间】:2010-05-28 21:05:50
【问题描述】:

所以,我找到了一种将标签绑定到当前控件上的属性的方法

我给它起个名字:

<UserControl x:Class="WpfGridtest.GridControl" x:Name="GridControlControl1">

然后绑定到这个控件的属性:

<Label Content="{Binding ElementName=GridControlControl1, Path=Filter}"></Label>

我可以看到我放入该属性的默认值。

我猜这不起作用,因为我绑定到未实现 INotifyPropertyChanged 的 String 属性?

我是否应该为此属性使用其他类型,而不是 String 自动通知我的更改标签,或者我是否以错误的方式进行此操作?

【问题讨论】:

    标签: wpf binding inotifypropertychanged


    【解决方案1】:

    INotifyPropertyChanged 接口应由包含该属性的类实现 - 在本例中,由您的 WpfGridtest.GridControl 实现。

    另外,如果您想将属性用于 UI,请考虑使用 DependencyProperty 作为存储而不是私有字段。

    【讨论】:

      【解决方案2】:

      另外,也有可能默认绑定方式是一次,所以你可能要在你的{Binding}改一下

      【讨论】:

      • 也尝试添加 NotifyOnSourceUpdated=True,但也没有任何变化
      猜你喜欢
      • 2013-05-31
      • 2015-09-27
      • 2012-01-29
      • 1970-01-01
      • 2010-10-16
      • 1970-01-01
      • 1970-01-01
      • 2019-12-17
      • 1970-01-01
      相关资源
      最近更新 更多