0

I have a TreeView control. It has a SelectedItemChanged event handler. In this event handler, the sender parameter comes in as a TreeView. When expanding and investigating the datatips for sender, it displays a property 'SelectedContainer' as ((System.Windows.Controls.TreeView)(sender)).SelectedContainer

I can not find this property anywhere. So where does it come from?
Is this property accessible to me?

playerone
  • 127
  • 1
  • 8

1 Answers1

1

It's internal. From Reflector:

    internal TreeViewItem SelectedContainer
    {
        [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
        get
        {
            return this._selectedContainer;
        }
    }

You should be able to get the container from the ItemContainerGenerator:

    var treeViewItem = (TreeViewItem)treeView.ItemContainerGenerator.ContainerFromItem(treeView.SelectedItem);
JimSt24
  • 186
  • 5
  • Note: the ItemContainerGenerator is not doing a recursive search, but only looks in the top layer. There's a recursive extension method in this thread: https://social.msdn.microsoft.com/forums/silverlight/en-us/84cd3a27-6b17-48e6-8f8a-e5737601fdac/treeviewitemcontainergeneratorcontainerfromitem-returns-null?forum=silverlightnet – benk Oct 11 '22 at 16:25