dotnet/Documentation/compatibility/wpf-treeviewitem-must-be-us...

2.4 KiB

WPF TreeViewItem must be used within a TreeView

Scope

Minor

Version Introduced

4.5

Source Analyzer Status

Available

Change Description

A change was introduced in 4.5 that restricts usage of xref:System.Windows.Controls.TreeViewItem?displayProperty=name elements outside of a xref:System.Windows.Controls.TreeView?displayProperty=name. This manifests under the following conditions:

In other words, this is seen when a xref:System.Windows.Controls.TreeViewItem?displayProperty=name is used outside of a xref:System.Windows.Controls.TreeView?displayProperty=name, and the user clicks on a descendant of the xref:System.Windows.Controls.TreeViewItem?displayProperty=name to bring it into view. If the xref:System.Windows.Controls.TreeViewItem?displayProperty=name has no focusable descendants, you'll never see this issue. An example of a situation where this is hit is when a xref:System.Windows.Controls.TreeViewItem?displayProperty=name is the root of a DataTemplate. When this issue is hit, there is an InvalidCastException that occurs within the WPF framework.

  • Quirked
  • Build-time break

A hotfix will be made available for this.

Affected APIs

  • Not detectable via API analysis

Category

Windows Presentation Foundation (WPF)