I have never come across this issue but most recently I noticed that a two way binding to a property doesn't work if the property resides in a Singleton.
What I mean is that the 'other' CheckBox
never updates its value.
Any ideas on how to make it work? Thanks in advance!
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}" />