DataTrigger 和变量绑定实例 让一个Ellipse的Fill颜色与变量绑定 Label的Contnet与变量关联

 1 <Ellipse
 2     MinWidth="30"
 3     MinHeight="30"
 4     HorizontalAlignment="Center"
 5     VerticalAlignment="Center">
 6     <Ellipse.Style>
 7         <Style TargetType="{x:Type Ellipse}">
 8             <!--<Setter Property="Fill" Value="Red" />-->
 9             <Style.Triggers>
10                 <DataTrigger Binding="{Binding SerialClosed}" Value="false">
11                     <Setter Property="Fill" Value="Red" />
12                 </DataTrigger>
13                 <DataTrigger Binding="{Binding SerialClosed}" Value="true">
14                     <Setter Property="Fill" Value="Gray" />
15                 </DataTrigger>
16             </Style.Triggers>
17         </Style>
18     </Ellipse.Style>
19 </Ellipse>
 1 <Label
 2     Grid.Column="1"
 3     FontSize="30">
 4     <Label.Style>
 5         <Style TargetType="Label">
 6             <Style.Triggers>
 7                 <DataTrigger Binding="{Binding SerialClosed}" Value="false">
 8                     <Setter Property="Content" Value="关闭" />
 9                 </DataTrigger>
10                 <DataTrigger Binding="{Binding SerialClosed}" Value="true">
11                     <Setter Property="Content" Value="打开" />
12                 </DataTrigger>
13             </Style.Triggers>
14         </Style>
15     </Label.Style>
16 </Label>

 

posted @ 2023-12-20 09:29  无处不在-超超  阅读(43)  评论(0编辑  收藏  举报