2010-12-05 9 views
2

以下のXAMLを使用して、ウィンドウ内のすべてのTextBoxの境界を赤色のOnMouseOverに設定しようとしています。マウスがテキストボックスの上にあるとき、FontSizeとForegroundのプロパティは設定されていますが、BorderBrushは以前のデフォルト値に戻す前に一時的にのみ設定されます。私は、BorderBrushをマウスがテキストボックスの上になくなるまで赤くしておきたい。これがどうして起こるのか?WPF BorderBrush on TextBoxは、一度IsMouseOverトリガに設定されています。

<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> 

答えて

0

IsMouseOverプロパティがtrueに設定されている場合、TextBoxにBorderBrushの別のアニメーションがあると仮定します。ただし、このトリガーは、BorderThicknessが1.0の場合にのみ有効です。これを克服するには、BorderThicknessを1.01またはトリガーの何かに変更することができます.BorderBrushはマウスがTextBox上にある限り赤色のままです。

<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> 
関連する問題