鼠标输入时,WPF文本框边框会改变颜色

时间:2016-10-17 13:57:47

标签: c# wpf visual-studio textbox border

由于某些原因,只要鼠标悬停在文本框上,我的文本框边框就会将颜色更改为输出蓝色。这是我的xaml:

 <TextBox 
   BorderThickness="1" 
   BorderBrush="Black" 
   x:Name="textBox" 
   custom:ScrollToEndBehavior.OnTextChanged="True" 
   VerticalScrollBarVisibility="Auto" 
   HorizontalAlignment="Center" 
   Height="154" 
   Margin="32,220,36,5" 
   TextWrapping="Wrap" 
   Text="{Binding LogText, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"  
   Width="449" 
   Background="WhiteSmoke" 
   Visibility="{Binding Path=IsLogVisible, Converter={StaticResource BoolToVis}}" 
   IsReadOnly="True"/>

1 个答案:

答案 0 :(得分:1)

使用IsMouseOver触发器将默认样式更改为黑色:

<Style TargetType="TextBox">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="TextBox">
                    <Border BorderThickness="{TemplateBinding Border.BorderThickness}"
                  BorderBrush="{TemplateBinding Border.BorderBrush}"
                  Background="{TemplateBinding Panel.Background}"
                  Name="border"
                  SnapsToDevicePixels="True">
                        <ScrollViewer HorizontalScrollBarVisibility="Hidden"
                           VerticalScrollBarVisibility="Hidden"
                           Name="PART_ContentHost"
                           Focusable="False" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="UIElement.IsMouseOver" Value="True">
                            <Setter Property="Border.BorderBrush" TargetName="border" 
                    Value="Black"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>