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?
Would this work?
public Whatever StapelStatus
{
get { return _stapelStatus; }
set
{
_stapelStatus = value;
OnPropertyChanged("StapelStatus");
StatusColor = value == StapelStatus.Neu ? new SolidColorBrush(Colors.CornflowerBlue) : new SolidColorBrush(Colors.DarkOrange);
}
}
public Brush StatusColor
{
get { return _statusColor; }
set
{
_statusColor = value;
OnPropertyChanged("StatusColor");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With