【发布时间】:2012-06-19 18:44:09
【问题描述】:
我从来没有遇到过这个问题,但最近我注意到如果属性驻留在 Singleton 中,则双向绑定到属性不起作用。
我的意思是“其他”CheckBox 永远不会更新它的值。
关于如何使它工作的任何想法? 提前致谢!
Singleton.cs
public class Singleton : INotifyPropertyChanged
{
private bool panelClosed;
static Singleton()
{
Instance = new Singleton();
}
public event PropertyChangedEventHandler PropertyChanged;
public static Singleton Instance { get; private set; }
public bool PanelClosed
{
get
{
return this.panelClosed;
}
set
{
this.panelClosed = value;
this.NotifyPropertyChanged("PanelClosed");
}
}
private void NotifyPropertyChanged(string info)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(null, new PropertyChangedEventArgs(info));
}
}
}
XAML:
<CheckBox
Content="Check/Uncheck me"
Height="16" Name="checkBox1"
IsChecked="{Binding Source={x:Static local:Singleton.Instance}, Path=PanelClosed,
UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
<CheckBox
Content="Sanity Check"
Height="16" Name="checkBox2"
IsChecked="{Binding Source={x:Static local:Singleton.Instance}, Path=PanelClosed,
UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
【问题讨论】: