开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜