Hi
I am examining whether this function can be mounted with XamTree.
1.Whether cursor under TreeItem exists when right-clicking in the xamTree area is checked.
Problem 1 XamTree.MouseLeftButtonDown Event is not generated even if it clicks at the cursor position of figure above.
2.Whether cursor under TreeItem exists when left-clicking in the xamTree area is checked. I tried to treat MouseRightButtonDown, and to acquire XamTreeItem that is below referring to the MouseButtonEventArgs object. but, Problem 2 The type of OriginalSource when right-clicking outside the area of TextBlock of item7 cannot be judged as shown in figure above. I want to check whether there is XamTreeItem in the clicked area.
by handling XamGrid.MouseLeftButtonDown Event ,XamGrid.MouseRightButtonDown EventCan TreeItem under the cursor be checked?
Please cooperate if there is a good method of settlement. Sorry to trouble you. Thank you for taking care of it.
regards.
Settlement of the issue:
I retrieve TreeViewItem of VisualTreeHelper by using e.OriginalSource.
static method: static DependencyObject VisualUpwardSearch<T>(DependencyObject source) { while (source != null && source.GetType() != typeof(T)) source = VisualTreeHelper.GetParent(source);
return source; } MouseLeftButtonDown Event:
private void xamTreeEx_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { XamTreeItem treeViewItem = VisualUpwardSearch<XamTreeItem>(e.OriginalSource as DependencyObject) as XamTreeItem;
if (treeViewItem != null) { //When there is XamTreeItem in the area } else { //When there is no XamTreeItem in the area }
}
Thus, I was able to check whether XamTreeItem existed in the clicked area. The problem was solved.