关于TextBox控件字体颜色绑定

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

2.几个注意点

<Style TargetType="{x:Type TextBox}">  是将风格指向TextBox,没有这句话,就不能继承TextBox控件的基本风格。

 

posted @ 2018-03-15 22:36  <--青青子衿-->  阅读(2299)  评论(0)    收藏  举报
// /**/ // 在页脚Html代码 引入 // function btn_donateClick() { var DivPopup = document.getElementById('Div_popup'); var DivMasklayer = document.getElementById('div_masklayer'); DivMasklayer.style.display = 'block'; DivPopup.style.display = 'block'; var h = Div_popup.clientHeight; with (Div_popup.style) { marginTop = -h / 2 + 'px'; } } function MasklayerClick() { var masklayer = document.getElementById('div_masklayer'); var divImg = document.getElementById("Div_popup"); masklayer.style.display = "none"; divImg.style.display = "none"; } setTimeout( function () { document.getElementById('div_masklayer').onclick = MasklayerClick; document.getElementById('btn_donate').onclick = btn_donateClick; var a_gzw = document.getElementById("guanzhuwo"); a_gzw.href = "javascript:void(0);"; $("#guanzhuwo").attr("onclick","follow('33513f9f-ba13-e011-ac81-842b2b196315');"); }, 900);