Skip to content

WPF controls in a RowVirtualized DataGrid control lose their value after scrolling #1541

Closed
@SamBent

Description

@SamBent

(Port of recent .NETFx servicing fix)
ComboBox (or any Selector) displays the wrong value for SelectedValue (or any selection property) when

  1. ComboBox is declared in a cell template of a DataGrid
  2. Both ItemsSource and SelectedValue are bound to the row's data item via implicit DataContext (as opposed to explicit Source, ElementName, RelativeSource, etc.)
  3. DataGrid row virtualization is enabled.
  4. 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.

Metadata

Metadata

Assignees

Labels

.NET FrameworkBugProduct bug (most likely)tell-modeIssues and PR's that require notice to .NET Core Shiproom

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions