WPF 触发器

 1.属性触发器

主要用于依赖属性

< Style.Triggers >
                    
< Trigger  Property ="IsMouseOver"  Value ="True" >
                        
< Setter  Property  ="Background"  Value ="Green" />
                    
</ Trigger >
</ Style.Triggers >

2.MultiTrigger

满足多个条件的时候才触发

 

< MultiTrigger >
    
< MultiTrigger.Conditions >
      
< Condition  Property ="HasItems"  Value ="false"   />
      
< Condition  Property ="Width"  Value ="Auto"   />
    
</ MultiTrigger.Conditions >
    
< Setter  Property ="MinWidth"  Value ="120" />
  
</ MultiTrigger >


3.DataTrigger

可用于非依赖属性,即可用于普通的用户自定义的.net属性,特点是多了个Binding

       < DataTrigger  Binding =" {Binding Path=State} "  Value ="WA" >
        
< Setter  Property ="Foreground"  Value ="Red"   />
      
</ DataTrigger >     
      
< MultiDataTrigger >
        
< MultiDataTrigger.Conditions >
          
< Condition  Binding =" {Binding Path=Name} "  Value ="Portland"   />
          
< Condition  Binding =" {Binding Path=State} "  Value ="OR"   />
        
</ MultiDataTrigger.Conditions >
        
< Setter  Property ="Background"  Value ="Cyan"   />
      
</ MultiDataTrigger >


4.EventTrigger

由RoutedEvent触发后 以动画来响应

<EventTrigger RoutedEvent="Mouse.MouseLeave">
  
<EventTrigger.Actions>
    
<BeginStoryboard>
      
<Storyboard>
        
<DoubleAnimation
          
Duration="0:0:1"
          Storyboard.TargetProperty
="MaxHeight"  />
      
</Storyboard>
    
</BeginStoryboard>
  
</EventTrigger.Actions>
</EventTrigger>

你可能感兴趣的:(.net,WPF)