WPF TextBox 在聚焦时具有蓝色轮廓
WPF TextBox has Blue Outline while in focus
所以我正在 WPF 中开发一个程序,我制作了一个文本框,当它没有聚焦时没有边框,并且(应该)在聚焦时有一条黑线。但是,该行显示为蓝色。我环顾四周 Google,似乎没有任何效果。
<Window x:Class="RequestApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:RequestApp"
mc:Ignorable="d"
Title="MainWindow" Height="900.156" Width="1414.292">
<Window.Resources>
<Style TargetType="TextBox">
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="Text" Value="Come Jam wit me man" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="7*"/>
<RowDefinition Height="18*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1067*"/>
<ColumnDefinition Width="433*"/>
</Grid.ColumnDefinitions>
<TextBox x:Name="Request" HorizontalAlignment="Left" Margin="37,130,0,0" BorderThickness="0" Text="Request" VerticalAlignment="Top" RenderTransformOrigin="-2.971,0.656" Height="39" Width="594" FontFamily="Modern Sans" FontSize="25" InputScope="Default" GotFocus="Request_GotFocus" LostFocus="Request_LostFocus" SelectionBrush="{x:Null}" BorderBrush="Black" Foreground="Gray"/>
</Grid>
PS: 我不知道第一件事XAML
以下是文本框的默认样式。您正在对抗的行为是由这两个 ControlTemplate 触发器引起的 - IsMouseOver 和 IsKeyboardFocused。只需根据需要编辑纯色画笔定义即可:
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" TargetName="border" Value="0.56"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.MouseOver.Border}"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.Focus.Border}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>
<Condition Property="IsSelectionActive" Value="false"/>
</MultiTrigger.Conditions>
<Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
</MultiTrigger>
</Style.Triggers>
</Style>
我在寻找一种方法来消除 WPF 文本框中显示为蓝色且不适合我的设计的边框后发现了这个问题。
我通过将 Border-Thickness 设置为“0”来完成此操作:
<TextBox x:Name="textBoxSearch" BorderThickness="0"/>
所以我正在 WPF 中开发一个程序,我制作了一个文本框,当它没有聚焦时没有边框,并且(应该)在聚焦时有一条黑线。但是,该行显示为蓝色。我环顾四周 Google,似乎没有任何效果。
<Window x:Class="RequestApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:RequestApp"
mc:Ignorable="d"
Title="MainWindow" Height="900.156" Width="1414.292">
<Window.Resources>
<Style TargetType="TextBox">
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="Text" Value="Come Jam wit me man" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="7*"/>
<RowDefinition Height="18*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1067*"/>
<ColumnDefinition Width="433*"/>
</Grid.ColumnDefinitions>
<TextBox x:Name="Request" HorizontalAlignment="Left" Margin="37,130,0,0" BorderThickness="0" Text="Request" VerticalAlignment="Top" RenderTransformOrigin="-2.971,0.656" Height="39" Width="594" FontFamily="Modern Sans" FontSize="25" InputScope="Default" GotFocus="Request_GotFocus" LostFocus="Request_LostFocus" SelectionBrush="{x:Null}" BorderBrush="Black" Foreground="Gray"/>
</Grid>
PS: 我不知道第一件事XAML
以下是文本框的默认样式。您正在对抗的行为是由这两个 ControlTemplate 触发器引起的 - IsMouseOver 和 IsKeyboardFocused。只需根据需要编辑纯色画笔定义即可:
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" TargetName="border" Value="0.56"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.MouseOver.Border}"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.Focus.Border}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>
<Condition Property="IsSelectionActive" Value="false"/>
</MultiTrigger.Conditions>
<Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
</MultiTrigger>
</Style.Triggers>
</Style>
我在寻找一种方法来消除 WPF 文本框中显示为蓝色且不适合我的设计的边框后发现了这个问题。
我通过将 Border-Thickness 设置为“0”来完成此操作:
<TextBox x:Name="textBoxSearch" BorderThickness="0"/>