public class Person
{
RoutedEvent NameChangedEvent = EventManager.RegisterRoutedEvent("NameChanged", RoutingStrategy.Bubble,typeof(RoutedEventHandler),typeof(Person));
 
        //为界面添加路由侦听
AddNameChangedHandle(DependencyObject d,RoutedEventHandler h)
{
UIElement e = d as UIElement;
            if(null!=e)
{
e.AddHandler(NameChangedEvent, h);
}
}
        //移除侦听
RemoveNameChangedHandle(DependencyObject d,RoutedEventHandler h)
{
UIElement e = d as UIElement;
            if(null!=e)
{
e.RemoveHandler(NameChangedEvent,h);
}
}
Id { get; set; }
Name { get; set; }
}
 
 
 
<Window x:Class="WpfApplication1.Window27"
 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 
Title="Window27" Height="272" Width="349">
 
x:Name="gd_main">
 
Content="Button"  x:Name="button1" Width="75" Height="75" Margin="10" Click="button1_Click" />
 
    </Grid>
 
</Window>
 
 
 
 
 
 
 
 
: Window
 
{
 
        public Window27()
 
{
 
InitializeComponent();
 
            //为外层Grid添加路由事件
 
Person.AddNameChangedHandle(this.gd_main, new RoutedEventHandler(PersonNameChanged));
 
}
 
 
 
 
 
PersonNameChanged(object obj, RoutedEventArgs e)
 
{
 
MessageBox.Show((e.OriginalSource as Person).Name);
 
}
 
 
 
button1_Click(object sender, RoutedEventArgs e)
 
{
 
Person persion = new Person();
 
persion.Id = 0;
 
persion.Name = "Darren";
 
            //准备事件消息并发送路由事件
 
RoutedEventArgs arg = new RoutedEventArgs(Person.NameChangedEvent, persion);
 
            this.button1.RaiseEvent(arg);
 
}
 
}