I had a variable which was not static and INotifyPropertyChanged implemented succesfully. Then I tried to make it global, so turned it a static variable. But this time, INot
Very good example, I used it for some general settings in application, when I want to bind some property online to components
public sealed class DataGridClass:INotifyPropertyChanged
{
private static readonly DataGridClass instance = new DataGridClass();
private DataGridClass() { }
public static DataGridClass Instance
{
get
{
return instance;
}
}
private int _DataGridFontSize {get;set;}
public int DataGridFontSize
{
get { return _DataGridFontSize; }
set { _DataGridFontSize = value;
RaisePropertyChanged("DataGridFontSize");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string name)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
Set startup properties:
DataGridClass.Instance.DataGridFontSize = 14(or read from xml)
Bind this to components properties
xmlns:static="clr-namespace:MyProject.Static"
When you change this value somewhere in application like "Preferences"->DataGrid FontSize - to it automatically update this property for bindings with UpdateSourceTrigger
private void comboBoxFontSize_DropDownClosed(object sender, EventArgs e)
{
DataGridClass.Instance.DataGridFontSize = Convert.ToInt32(comboBoxFontSize.Text);
}