我从来没有遇到过这个问题,但最近我注意到如果属性驻留在 Singleton 中,则两种方式绑定到属性不起作用。
我的意思是“其他”CheckBox
永远不会更新它的价值。
关于如何使其工作的任何想法?提前致谢!
单例.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}" />