Intersoft ClientUI Documentation
How to: Mark a Routed Event as Handled

This example shows how to mark a routed event as handled by settings its Handled property of the event data to True.

Example

Description

When a routed event is marked as handled, it will stop the event propagation for the listeners defined in the XAML or in the code that uses language-specific operators. For more information about the concept of Handled in routed event, see Routed Events Overview.

The following code examples shows how to mark a routed event as handled by setting its Handled property to True.

Code

XAML
Copy Code
<Grid x:Name="LayoutRoot">
        <StackPanel>
            <Intersoft:UXTextBox Name="textBox1" Width="150" HorizontalAlignment="Left"/>
            <TextBlock Name="statusText" Width="200" HorizontalAlignment="Left"/>
        </StackPanel>
</Grid>
C#
Copy Code
using System.Windows;
using Intersoft.Client.Framework;
using Intersoft.Client.UI.Navigation;
using CoreInput = Intersoft.Client.Framework.Input;

namespace ClientUIApplication_Docs.RoutedEvents
{
    public partial class BubblingEvent : UXPage
    {
        public BubblingEvent()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(BubblingEvent_Loaded);
        }

        void BubblingEvent_Loaded(object sender, RoutedEventArgs e)
        {
            // Handle the PreviewKeyDown routed event in the LayoutRoot (Grid) element
            LayoutRoot.AddHandler(CoreInput.Keyboard.PreviewKeyDownEvent, new CoreInput.KeyEventHandler(OnPreviewKeyDown));
        }

        void OnPreviewKeyDown(object sender, CoreInput.KeyEventArgs e)
        {
            // Mark a routed event as handled by setting 
            // the Handled property of the event data to true
            
            e.Handled = true;
        }
    }
}
See Also

Concepts

Other Resources