1.通过WPF绑定一个属性,比如bool型的数据

 <TextBox BorderBrush="Transparent" 
                                         Text="{Binding Path=DataContent,Mode=OneWay,UpdateSourceTrigger=LostFocus}"                                               
                                         HorizontalContentAlignment="Left"
                                         Padding="5,0,0,0"
                                         VerticalContentAlignment="Center"
                                         VerticalAlignment="Stretch"                                         
                                         IsReadOnly="True">

                                            <TextBox.Style>
                                                <Style TargetType="{x:Type TextBox}">
                                                    <Style.Triggers>

                                                        <DataTrigger Binding="{Binding FrameColor}" Value="True">
                                                            <Setter Property="Foreground" Value="Red">                                                  </Setter>
                                                        </DataTrigger>

                                                        <DataTrigger Binding="{Binding FrameColor}" Value="False">
                                                            <Setter Property="Foreground" Value="Green"></Setter>
                                                        </DataTrigger>

                                                    </Style.Triggers>
                                                </Style>

                                            </TextBox.Style>

                                        </TextBox>
View Code

相关文章:

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