Bubble routed events, and write an event handler for a routed event. : RoutedCommand « Windows Presentation Foundation « C# / C Sharp






Bubble routed events, and write an event handler for a routed event.

Bubble routed events, and write an event handler for a routed event.
  

<StackPanel
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="WpfApplication1.RoutedEventHandle" Name="dpanel" Button.Click="HandleClick">
  <StackPanel.Resources>
      <Style TargetType="{x:Type Button}">
        <Setter Property="Height" Value="20"/>
        <Setter Property="Width" Value="250"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
      </Style>
  </StackPanel.Resources>
  <Button Name="Button1">Item 1</Button>
  <Button Name="Button2">Item 2</Button>
</StackPanel>
//File:Window.xaml.cs

using System;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;

namespace WpfApplication1
{
    public partial class RoutedEventHandle : StackPanel
    {
        void HandleClick(object sender, RoutedEventArgs args)
        {
            FrameworkElement fe = (FrameworkElement)sender;
            Console.WriteLine("Event handled by element named ");
            Console.WriteLine(fe.Name);
            FrameworkElement fe2 = (FrameworkElement)args.Source;
            Console.WriteLine("Event originated from source element of type ");
            Console.WriteLine(args.Source.GetType().ToString());
            Console.WriteLine(" with Name ");
            Console.WriteLine(fe2.Name);
            Console.WriteLine(args.RoutedEvent.RoutingStrategy);
        }
    }
}

   
    
  








Related examples in the same category

1.Create a custom RoutedCommand, the CommandBinding objects, and the KeyBinding objects in code.Create a custom RoutedCommand, the CommandBinding objects, and the KeyBinding objects in code.
2.Convert RoutedEventArgs.OriginalSource to event senderConvert RoutedEventArgs.OriginalSource to event sender
3.Get RoutedEvent NameGet RoutedEvent Name
4.Bind event handler to button with RoutedEventHandlerBind event handler to button with RoutedEventHandler
5.Custom Command by KeyGesture and RoutedUICommandCustom Command by KeyGesture and RoutedUICommand
6.RoutedEvents: Button Mouse Up EventRoutedEvents: Button Mouse Up Event
7.RoutedEvents: Drag And DropRoutedEvents: Drag And Drop
8.RoutedEvents: Focus eventRoutedEvents: Focus event
9.RoutedEvents: Key ModifiersRoutedEvents: Key Modifiers
10.RoutedEvents: Key Press EventsRoutedEvents: Key Press Events
11.RoutedEvents: Mouse PositionRoutedEvents: Mouse Position
12.RoutedEvents Only NumbersRoutedEvents Only Numbers
13.RoutedEvents: Tunneled Key PressRoutedEvents: Tunneled Key Press
14.Routed Event DemoRouted Event Demo
15.Create RoutedCommand from InputGestureCollection