Im my viewmodel I have a list of my custom objects of type IPC.Device
bound to a property defined as
private ObservableCollection<IPC.Device> _devices;
public ObservableCollection<IPC.Device> Devices
{
get
{
return _devices;
}
set
{
_devices = value;
RaisePropertyChangedEvent ("Devices");
}
}
I use the ObservableCollection to populate a DataGrid, that I create with the following XAML (unnecessary parts are not shown)
<DataGrid x:Name="MainGrid" ItemsSource="{Binding Path=Devices}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False">
<DataGrid.Columns>
....
<DataGridTemplateColumn Header="{Binding Source={x:Static p:Resources.device_status},
Converter={StaticResource CapitalizeFirstLetterConverter}}"
Width="*" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=deviceStatus, Converter={StaticResource DeviceStatusToStringConverter}, Mode=OneWay}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
....
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<Views:CameraLoginControl Visibility="{Binding Path=deviceStatus, Converter={StaticResource DeviceStatusUnauthorizedConverter}, Mode=OneWay}" />
<Views:TestSelectionControl Visibility="{Binding Path=deviceStatus, Converter={StaticResource DeviceStatusOnlineConverter}, Mode=TwoWay}" />
</StackPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
When I update the ObservableCollection byt replacing an item with its updated copy I can see that the Datagrid is correctly updated, the row is updated and the DeviceStatusToStringConverter
is fired. Unfortunately, the DeviceStatusUnauthorizedConverter
and DeviceStatusOnlineConverter
are never fired again, so the RowDetailsTemplate is still the one of the previous item.
What am I doing wrong?
Update
The IPC.Device
is, stripped of unnecessary fields:
public class Device
{
[DataMember]
public DeviceStatus deviceStatus { get; set; }
...
}
You see [DataMember]
beacsue I use this structure in many places, also for IPC. I have other Propertied marked [DataMember]
, thus I would exclude this as the reason why this happens. DeviceStatus
is an enum.