Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > General Discussions > Can I prevent event routing for a specific control/event?

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

Feed from this thread
  • Stephan avatar

    Posted on Jan 27, 2012 (permalink)

    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

    Reply

  • Petar Mladenov Petar Mladenov admin's avatar

    Posted on Feb 1, 2012 (permalink)

    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 >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > General Discussions > Can I prevent event routing for a specific control/event?