今天有人问我关于datatrigger的问题,突然发现之前我居然都没有用过,罪过罪过。

  Trigger是最普遍常用的触发器,它只能检测依赖项属性的变化。当你需要检测一个系统变量或者是你自定义的属性的变化时,就需要用到datatrigger,它的触发源使用绑定机制,例如:

  <Style x:Key="textboxstyle" TargetType="TextBox">

    <Style.Triggers>

       <DataTrigger Binding="{Binding Source={x:Static SystemColors.WindowTextColor}}" Value="#FF000000">

         <Setter Property="Foreground" Value="Red"/>

       </DataTrigger>

    </Style.Triggers>

  </Style>

   同样,它可以绑定指定ElementName的任意属性,如textblock的text、Label的background等等。

 

相关文章:

  • 2021-12-24
  • 2021-09-10
  • 2022-12-23
  • 2022-01-03
  • 2022-01-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-06-07
  • 2022-02-04
相关资源
相似解决方案