2

ウィンドウ内のすべてのTextBoxの境界線を赤いOnMouseOverに設定しようとする以下のXAMLがあります。マウスをテキストボックスの上に置くと、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>
4

1 に答える 1

0

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>
于 2010-12-05T20:54:21.380 に答える