问题
I have a TreeViewItem
. I'd like to get parent node of this item if any.
However TreeViewItem.ParentTreeViewItem
property is internal, and thus not accessible.
There is no reason to hide this property from developers, however, someone very smart decided that way.
How do I proceed? Is there any workarounds (reflection on private members is not working in SL)?
回答1:
Found an ugly, but working way:
static TreeViewItem GetParentItem(TreeViewItem item)
{
for (var i = VisualTreeHelper.GetParent(item); i != null; i = VisualTreeHelper.GetParent(i))
if (i is TreeViewItem)
return (TreeViewItem)i;
return null;
}
So much wasted CPU cycles because of hidden readonly property :(
来源:https://stackoverflow.com/questions/4246159/silverlight-determine-parent-treeviewitem