A very good example, I used it for some general settings in the 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 launch properties:
DataGridClass.Instance.DataGridFontSize = 14(or read from xml)
Bind this to component properties
xmlns:static="clr-namespace:MyProject.Static" <extgrid:ExtendedDataGrid x:Name="testGrid" ClipboardCopyMode="IncludeHeader" AutoGenerateColumns="False"> <extgrid:ExtendedDataGrid.Resources> <Style TargetType="{x:Type DataGridCell}"> <Setter Property="FontSize" Value="{Binding Source={x:Static static:DataGridClass.Instance}, Path=DataGridFontSize, Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"/> </Style> </extgrid:ExtendedDataGrid.Resources>
When you change this value somewhere in the application, for example, Preferences → DataGrid FontSize, it automatically updates this property for bindings using UpdateSourceTrigger
private void comboBoxFontSize_DropDownClosed(object sender, EventArgs e) { DataGridClass.Instance.DataGridFontSize = Convert.ToInt32(comboBoxFontSize.Text); } <ComboBox Grid.Column="1" Grid.Row="0" Height="21" Width="75" Name="comboBoxFontSize" HorizontalAlignment="Left" VerticalAlignment="Center" DropDownClosed="comboBoxFontSize_DropDownClosed" ItemsSource="{Binding Source={x:Static commands:ConstClass.ListOfFontSize},Mode=OneWay}" SelectedItem="{Binding Source={x:Static static:DataGridClass.Instance},Path=DataGridFontSize, Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"/>
source share