首页 > 代码库 > [WPF] 圆角TextBox
[WPF] 圆角TextBox
使用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>
[WPF] 圆角TextBox
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。