How to style a WPF DataGridCell dynamically
I have a DataGrid with the itemsSource defined as follow: dg.ItemsSource = new ObservableCollection<myRow> ... public class myRow : Collection<myDataGridCell> { ... } ... public interface ImyDataGridCell { Brush Background { get; set; } Brush Foreground { get; set; } } and then I have classes for each type of column/cell: public class myTextBoxColumn : DataGridTextColumn {...} public class myTextBoxCell : TextBox, ImyDataGridCell {...} then I set each column's CellStyle like this: in each column's constructor: string source = String.Format(CultureInfo.InvariantCulture, "[{0}].", dataGrid