I am replacing a TreeView control with a RadTreeView control however I have run in to a issue. I want the user to be able to click on the body of the TreeView (instead of a node) and have it deselect the item in the tree view.
With the original TreeView I would do
<
TreeView
Grid.Row
=
"0"
MouseDown
=
"TreeView_OnMouseDown"
>
<
TreeViewItem
Header
=
"Item 1"
/>
<
TreeViewItem
Header
=
"Item 2"
/>
</
TreeView
>
Then in the code behind I would have
private
void
TreeView_OnMouseDown(
object
sender, MouseButtonEventArgs e)
{
var treeView = (TreeView)sender;
var items = treeView.Items.Cast<TreeViewItem>();
foreach
(var treeViewItem
in
items)
{
treeViewItem.IsSelected =
false
;
}
}
And this would work correctly. However if I do
<
telerik:RadTreeView
Grid.Row
=
"1"
MouseDown
=
"RadTreeView_OnMouseDown"
>
<
telerik:RadTreeViewItem
Header
=
"Item 3"
/>
<
telerik:RadTreeViewItem
Header
=
"Item 4"
/>
</
telerik:RadTreeView
>
and
private
void
RadTreeView_OnMouseDown(
object
sender, MouseButtonEventArgs e)
{
var treeView = (RadTreeView)sender;
treeView.SelectedItem =
null
;
MessageBox.Show(
"RadTreeView_OnMouseDown fired!"
);
}
the OnMouseDown event never fires.
Looking at the OnMouseDown event with Snoop it appears to be getting marked as handled by the ScrollViewer inside the RadListView.
What is the correct way to deselect the node when clicking on the body of the tree view? Attached is a simple example program that shows the two controls side by side with their different behaviors.