在Button样式中添加EventSetter,理解路由事件

时间:2022-05-30 19:13:32

XAML

 

< Window.Resources >
< Style  x:Key ="ButtonStyle2"  TargetType =" {x:Type Button} " > 
             < EventSetter  Event ="Click"  Handler ="b1SetColor" /> 
         </ Style >
     </ Window.Resources >

< Button  x:Name ="butrouter"            Style =" {DynamicResource ButtonStyle2} "   Click ="butrouter_Click"   />
 

 

CS

 

  private  void butrouter_Click( object sender, System.Windows.RoutedEventArgs e)
        {
             //  TODO: Add event handler implementation here.
        }
        
          private  void b1SetColor( object sender, System.Windows.RoutedEventArgs e)
        {
             //  TODO: Add event handler implementation here.

        }

 

先执行butrouter_Click,再执行b1SetColor