This is a migrated thread and some comments may be shown as answers.

Can I prevent event routing for a specific control/event?

1 Answer 38 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 27 Jan 2012, 09:37 AM
Let's say I've got several nested RadTreeViewItems but only the most outer RadTreeViewItem has an event handler attached to "Click". Now if any of the nested RadTreeViewItems is clicked, the outer event handler is triggered as well since, by default, the event bubbles up the visual tree.

Is there any way to prevent this, e.g. by setting an attached property with RoutingStrategy=Direct to all nested RadTreeViewItems?
The only workaround I'm currently aware of is to attach a dummy event handler to nested items which does nothing.

Regards,
Stephan

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 01 Feb 2012, 09:54 AM
Hi Stephan ,

 I don't believe an approach with attached property is possible. Usually, this is achieved with preview events. Since there are no PreviewClick events in the RadTreeView, you can just attach to the Click event of the first child like so:

<telerik:RadTreeViewItem Header="Item A" Click="A_Item_Click_1">
               <telerik:RadTreeViewItem Header="Item B" Click="B_Item_Click">
                   <telerik:RadTreeViewItem Header="Item C" />
                       <telerik:RadTreeViewItem Header="Item D" />
               </telerik:RadTreeViewItem>
           </telerik:RadTreeViewItem>
private void B_Item_Click(object sender, Telerik.Windows.RadRoutedEventArgs e)
       {         
           e.Handled = true;
       }
This way you are stopping all invokations of "A_Item_Click_1" when an item different from Item A is clicked.
Regards,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
General Discussions
Asked by
Marc
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or