Description
(Port of recent .NETFx servicing fix)
ComboBox (or any Selector) displays the wrong value for SelectedValue (or any selection property) when
- ComboBox is declared in a cell template of a DataGrid
- Both ItemsSource and SelectedValue are bound to the row's data item via implicit DataContext (as opposed to explicit Source, ElementName, RelativeSource, etc.)
- DataGrid row virtualization is enabled.
- Item is re-virtualized, then de-virtualized. E.g. scrolling it out of view, then back in.
Root cause:
Re-virtualization causes the item's UI to be disconnected. This sets DataContext to {DisconnectedItem}, which should set ItemsSource to null and leave SelectedValue unchanged, while removing property-changed listeners and other similar cleanup. But if ItemsSource happens first, Selector tries to change SelectedValue (to null). In a DataGrid, this records null as the "proposed value" of SelectedValue, (awaiting writing to the data item when the row-edit is committed). When the item is later de-virtualized, the cell displays the proposed value (null).
Fix: Selector should not change its selection properties, when reacting to being disconnected.