鼠标输入时,WPF文本框边框会改变颜色(WPF text box border changes color upon mouse entry)

出于某种原因,只要鼠标悬停在文本框上,我的文本框边框就会将颜色更改为输出蓝色。 这是我的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"/>

For some reason my text box border is changing color to an offputting blue whenever the mouse hovers over the text box. here is my 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"/>
更新时间:2022-06-15 08:06
最满意答案
 使用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>

Change the default style to black with a IsMouseOver trigger: 
<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>

你可能感兴趣的:(wpf,计算机外设)