开发者

Binding c# xaml element depending on value

开发者 https://www.devze.com 2023-03-18 09:29 出处:网络
I have <TextBlock Text=\"{Binding TexT}\" Style=\"{StaticResource PhoneTextNormalStyle}\"/> Also have {Binding Read_State} (bool Read_State)

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 bl开发者_StackOverflowue if Read_State==false?


You need to use a DataTrigger in a style for your TextBlock:

<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).

0

精彩评论

暂无评论...
验证码 换一张
取 消