#583 – Interrupting the Routing Process

We saw that a routed event in WPF can be routed up or down the logical and visual trees, being seen by any element in the hierarchy that chooses to handle the event.

In the diagram below, a KeyDown event is routed up the tree.

Any of the event handlers that intercept this event can choose to indicate that they have handled the event, by setting the Handled property of the KeyEventArgs argument to true.  When this happens, the event will not continue propagating up (or down) the tree.

        private void tbLawrence_KeyDown(object sender, KeyEventArgs e)
            DumpInfo("tbLawrence_KeyDown", sender, e.Source);

        private void spLawrence_KeyDown(object sender, KeyEventArgs e)
            DumpInfo("spLawrence_KeyDown", sender, e.Source);
            e.Handled = true;    // The event stops here

        private void spMain_KeyDown(object sender, KeyEventArgs e)
            DumpInfo("spMain_KeyDown", sender, e.Source);

        private void winMain_KeyDown(object sender, KeyEventArgs e)
            DumpInfo("winMain_KeyDown", sender, e.Source);


About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #583 – Interrupting the Routing Process

  1. DineshRajan says:


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: