简体   繁体   English

根据值绑定 c# xaml 元素

[英]Binding c# xaml element depending on value

I have <TextBlock Text="{Binding TexT}" Style="{StaticResource PhoneTextNormalStyle}"/> Also have {Binding Read_State} (bool Read_State) How I can change color of TextBlock to blue if Read_State==false?我有<TextBlock Text="{Binding TexT}" Style="{StaticResource PhoneTextNormalStyle}"/>还有 {Binding Read_State} (bool Read_State) 如果 Read_State==false,如何将 TextBlock 的颜色更改为蓝色?

You need to use a DataTrigger in a style for your TextBlock:您需要在 TextBlock 的样式中使用 DataTrigger:

<TextBlock ...>
  <TextBlock.Style>
    <Style TargetType="TextBlock">
      <Style.Triggers>
        <DataTrigger Binding="{Binding Path=Read_State}" Value="False">
          <Setter Property="Background" Value="Blue" />
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </TextBlock.Style>
</TextBlock>

I would rename your PhoneTextNormalStyle to PhoneTextStyle and add the trigger to that style which would then handle both (or all states if there are more conditions).我会将您的 PhoneTextNormalStyle 重命名为 PhoneTextStyle 并将触发器添加到该样式,然后该样式将同时处理两者(或所有状态,如果有更多条件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM