## 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 elements outside of a . This manifests under the following conditions: - 's visual parent is not a panel. (A generated for a will have a panel as its parent) - The is a descendant of a acting as the "items host" for a list control (ListBox, DataGrid, ListView, etc.). Virtualization doesn't need to be enabled. - The is item-scrolling (`ScrollUnit="Item"`). - Someone calls `VirtualizingStackPanel.MakeVisible(v)` to scroll an element `v` into view. This can be done explicitly, or implicitly in a number of ways; perhaps the most common way is simply clicking on `v` to give it the keyboard focus. - The visual-parent chain from `v` to the passes through the . In other words, this is seen when a is used outside of a , and the user clicks on a descendant of the to bring it into view. If the has no focusable descendants, you'll never see this issue. An example of a situation where this is hit is when a 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 ### Recommended Action A hotfix will be made available for this. ### Affected APIs * Not detectable via API analysis ### Category Windows Presentation Foundation (WPF)