简体   繁体   English

WPF 中 TextBox 的内部样式不起作用

[英]Internal Styling of TextBox in WPF not working

I want to change the border color of a text box when a user hovers his/her mouse over it.当用户将鼠标悬停在文本框上时,我想更改文本框的边框颜色。 I tried this but failed.我试过这个但失败了。

<TextBox Name="a" Margin="20 50 50 150" >
    <TextBox.Resources>
        <Style TargetType="TextBox">
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="BorderBrush" Value="Red"></Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </TextBox.Resources>
</TextBox>

You put the style in the TextBox resource so it is not actually applied to it, it is only a resource.您将样式放在TextBox资源中,因此它实际上并未应用于它,它只是一个资源。 Try removing the resource tag, like this:尝试删除资源标签,如下所示:

<TextBox Name="a" Margin="20 50 50 150" >
            <Style TargetType="TextBox">
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="BorderBrush" Value="Red"></Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>
</TextBox>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM