码迷,mamicode.com
首页 > Windows程序 > 详细

[WPF] 圆角TextBox

时间:2014-12-20 22:06:45      阅读:470      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

使用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

标签:

原文地址:http://www.cnblogs.com/liuzeyuzh/p/4175873.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!