繁体   English   中英

在IsMouseOver触发器上设置后,TextBox上的WPF BorderBrush消失

[英]WPF BorderBrush on TextBox goes away once set on IsMouseOver Trigger

我有下面的XAML,它试图将窗口中所有TextBox的边框设置为红色OnMouseOver。 发生的情况是,当鼠标悬停在文本框上时,会设置FontSize和Foreground属性,但是BorderBrush仅在恢复为其先前的默认值之前暂时设置。 我希望BorderBrush保持红色,直到鼠标不再位于文本框中。 任何想法为什么会发生这种情况?

<Window x:Class="StylesApp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="Width" Value="250" />
            <Setter Property="Height" Value="50" />
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="FontSize" Value="20" />
                    <Setter Property="Foreground" Value="Red" />
                    <Setter Property="BorderBrush" Value="Red" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
        <TextBox>
           My TextBox
        </TextBox>
    </Grid>
</Window>

当IsMouseOver属性设置为true时,我假定TextBox为BorderBrush提供了另一个动画。 但是,仅在BorderThickness恰好为1.0时才激活此触发器。 因此,要解决此问题,您可以将BorderThickness更改为1.01或在触发器中进行更改,只要鼠标悬停在TextBox上,BorderBrush就会保持红色。

<Style TargetType="{x:Type TextBox}">
    <Setter Property="Width" Value="250" />
    <Setter Property="Height" Value="50" />
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="BorderThickness" Value="1.01" />
            <Setter Property="FontSize" Value="20" />
            <Setter Property="Foreground" Value="Red" />
            <Setter Property="BorderBrush" Value="Red" />
        </Trigger>
    </Style.Triggers>
</Style>

暂无
暂无

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

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