在静态类中双向绑定到静态属性

时间:2012-10-25 13:58:22

标签: xaml binding static static-class two-way

严重不可能吗?我有解决方案将单向绑定到静态类中的属性,当然我有解决方案来绑定非静态类中的双向静态属性......但是......

我的意思是,解决方法很简单,我可以使用静态实例getter将静态类设置为单例(请参阅here),但是没有正确的方法吗?

我的班级看起来像这样:

public static class TestClass
{
  public static string TestProp {get; set;}
}

现在请假设我在setter中以“正常”方式正确实现了INotifyPropertyChanged(为简单起见,省略了)。

XAML应该如何绑定双向此属性? 感谢。

1 个答案:

答案 0 :(得分:-1)

这个答案可能会有所帮助: wpf static binding question 或这个: Binding to static class property

简而言之,您的案例看起来像:

{Binding Source={x:Static whatever:TestClass.TestProperty}, Path=.}