I have successfully bound a column in a DataGrid to an observable collection with objects implementing the INotifyPropertyChanged interface:
This is the xaml:
<dxg:GridColumn Name="Name" FieldName="Stapel" DisplayMemberBinding="{Binding Path=Name}" />
And the property in the objects class:
public string Name
{
get { return _name; }
set
{
if (value == _name) return;
_name = value;
OnPropertyChanged("Name");
}
}
But in another column I am using a Template:
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<Rectangle Height="19" Width="19" Fill="{Binding Path=Data.StatusColor}"></Rectangle>
</StackPanel>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
The Fill property of the rectangle is bound to a “calculated” property:
public SolidColorBrush StatusColor
{
get
{
if (StapelStatus == StapelStatus.Neu)
{
return new SolidColorBrush(Colors.CornflowerBlue);
}
return new SolidColorBrush(Colors.DarkOrange);
}
}
Some other property setters, which change the value of StapelStatus are calling
OnPropertyChanged("StatusColor");
I thought this would be enough to change also the color in the rectangle color in the grid column. But unfortunately when the StapelStatus is changed and OnPropertyChanged("StatusColor") is called the grid doesn’t reflect this change. I guess that I have to change somehow the binding in the DataTemplate. Can someone please give me an advice?
It was indeed a binding problem in the XAML. Unfortunately I did not set the FieldName property in the GridColumn. I thought the FieldName is only for use in normal GridColumns which don’t have any Template.
Below the working XAML for the column: