使用Blend编辑TextBox的Template,将其中的ListBoxChrome修改为Border。
1 <Application.Resources> 2 <LinearGradientBrush x:Key="TextBoxBorder" EndPoint="0,20" MappingMode="Absolute" StartPoint="0,0"> 3 <GradientStop Color="#ABADB3" Offset="0.05"/> 4 <GradientStop Color="#E2E3EA" Offset="0.07"/> 5 <GradientStop Color="#E3E9EF" Offset="1"/> 6 </LinearGradientBrush> 7 <Style x:Key="CornetTextBoxStyle" BasedOn="{x:Null}" TargetType="{x:Type TextBox}"> 8 <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 9 <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/> 10 <Setter Property="BorderBrush" Value="{StaticResource TextBoxBorder}"/> 11 <Setter Property="BorderThickness" Value="1"/> 12 <Setter Property="Padding" Value="1"/> 13 <Setter Property="AllowDrop" Value="true"/> 14 <Setter Property="FocusVisualStyle" Value="{x:Null}"/> 15 <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/> 16 <Setter Property="Stylus.IsFlicksEnabled" Value="False"/> 17 <Setter Property="Template"> 18 <Setter.Value> 19 <ControlTemplate TargetType="{x:Type TextBox}"> 20 <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true" CornerRadius="5"> 21 <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 22 </Border> 23 <ControlTemplate.Triggers> 24 <Trigger Property="IsEnabled" Value="false"> 25 <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> 26 <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 27 </Trigger> 28 </ControlTemplate.Triggers> 29 </ControlTemplate> 30 </Setter.Value> 31 </Setter> 32 <Style.Triggers> 33 <MultiTrigger> 34 <MultiTrigger.Conditions> 35 <Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/> 36 <Condition Property="IsSelectionActive" Value="false"/> 37 </MultiTrigger.Conditions> 38 <Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/> 39 </MultiTrigger> 40 </Style.Triggers> 41 </Style> 42 <!-- Resources scoped at the Application level should be defined here. --> 43 </Application.Resources>
时间: 2024-11-20 09:05:49