当TextBox是只读时,禁用焦点在tabstop上

时间:2014-10-14 04:18:05

标签: wpf xaml wpf-style

当TextBox处于readonly状态并且在tabbing上我想要禁用文本框的焦点边框时,我想在文本框的样式中执行此操作。任何人都可以帮我实现这一点吗?

更新了内容:

截图: enter image description here

2 个答案:

答案 0 :(得分:1)

在文本框样式中放置如下所示的条件

<MultiTrigger>
    <MultiTrigger.Conditions>
        <Condition Property="IsReadOnly" Value="True"></Condition>
        <Condition Property="IsFocused" Value="True"></Condition>               </MultiTrigger.Conditions>
    <MultiTrigger.Setters>
        <Setter Property="BorderBrush" Value="{#7B2F81}"></Setter>
    </MultiTrigger.Setters>

答案 1 :(得分:0)

试试这个:

<Window.Resources>
    <Style x:Key="FocusVisualStyle" TargetType="{x:Type Control}">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Control}">
                    <Border SnapsToDevicePixels="True" 
                            CornerRadius="0" 
                            BorderThickness="2"
                            BorderBrush="#7B2F81" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type TextBox}">
        <Setter Property="Background" Value="Pink" />

        <Style.Triggers>
            <Trigger Property="IsReadOnly" Value="True">
                <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisualStyle}" />
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Resources>

<Grid>
    <TextBox Text="TestText" 
             IsReadOnly="True"
             HorizontalAlignment="Center" 
             VerticalAlignment="Center" />
</Grid>

如果TextBox.IsReadOnly == True,请在StyleTrigger中设置FocusVisualStyle。您可以在FocusVisualStyle

中自定义Focus的视觉行为