只读时XAML文本框边框

时间:2014-11-20 15:40:50

标签: wpf xaml

我在下面的链接中遇到了同样的问题。没有答案。有人问过1年前

XAML textbox border goes away when changing isreadonly?

有人能帮助我吗?这是我现有的Textbox文件

<Style TargetType="TextBox" x:Key="StandardTextBox">
    <Style.Resources>
        <fawgCommon:ControlBackgroundConverter x:Key="BackgroundConverter" />
    </Style.Resources>
    <Setter Property="telerik:StyleManager.Theme" Value="{DynamicResource Theme}"/>
    <Setter Property="Background">
        <Setter.Value>
            <MultiBinding Converter="{StaticResource BackgroundConverter}">
                <Binding />
                <Binding Mode="OneTime"/>
            </MultiBinding>
        </Setter.Value>
    </Setter>
    <Setter Property="Foreground" Value="{DynamicResource CurrentThemeForegroundBrush}" />
    <Setter Property="CaretBrush" Value="{DynamicResource CurrentThemeForegroundBrush}" />
</Style>

1 个答案:

答案 0 :(得分:1)

不确定为什么这可能是一个问题,但在基本演示中,您可以使用一些触发器来监听IsReadOnly并正常设置TextBox的边框:

<TextBox IsReadOnly="True"  BorderThickness="1">
    <TextBox.Style>
       <Style TargetType="TextBox">
          <Style.Triggers>
             <Trigger Property="IsReadOnly" Value="True">
                <Setter Property="BorderBrush" Value="Blue"/>                    
             </Trigger>
          </Style.Triggers>
       </Style>
    </TextBox.Style>
</TextBox>

上面的示例最初将IsReadOnly设置为true,因此会显示一些蓝色边框。

<强> 更新

对于您发布的代码,它应该是这样的:

<Style TargetType="TextBox" x:Key="StandardTextBox">
  <Style.Resources>
    <fawgCommon:ControlBackgroundConverter x:Key="BackgroundConverter" />
  </Style.Resources>
  <Style.Triggers>
     <Trigger Property="IsReadOnly" Value="True">
         <Setter Property="BorderBrush" Value="Blue"/>
         <Setter Property="BorderThickness" Value="1"/>
     </Trigger>
  </Style.Triggers>
  <Setter Property="telerik:StyleManager.Theme" Value="{DynamicResource Theme}"/>
  <Setter Property="Background">
    <Setter.Value>
        <MultiBinding Converter="{StaticResource BackgroundConverter}">
            <Binding />
            <Binding Mode="OneTime"/>
        </MultiBinding>
    </Setter.Value>
  </Setter>
  <Setter Property="Foreground" 
          Value="{DynamicResource CurrentThemeForegroundBrush}" />
  <Setter Property="CaretBrush" 
          Value="{DynamicResource CurrentThemeForegroundBrush}" />
</Style>
相关问题