ControlTemple样式

1.TextBox 样式

1.1 style

 1    <Window.Resources>
 2         <Style x:Key="aa" TargetType="{x:Type TextBox}">
 3             <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
 4             <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
 5             <Setter Property="BorderThickness" Value="1"/>
 6             <Setter Property="Padding" Value="1"/>
 7             <Setter Property="AllowDrop" Value="true"/>
 8             <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
 9             <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
10             <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
11             <Setter Property="Template">
12                 <Setter.Value>
13                     <ControlTemplate TargetType="{x:Type TextBox}">
14                         <!--外边框颜色之类设置-->
15                         <Border x:Name="Bd"  CornerRadius="23" Padding="1" BorderBrush="#FFDDDDDD" BorderThickness="2"  >
16                             <Border.Effect>
17                                 <DropShadowEffect BlurRadius="10" Color="#FFE5F2FC" Direction="0" ShadowDepth="0"/>
18                             </Border.Effect>
19                             <!--这个Border主要用来遮挡框内的阴影,只要外阴影,如果只要内阴影不要外阴影,那么设置border的 ClipToBounds="True"  剪切外部内容,即可实现内阴影-->
20                             <Border Background="White" CornerRadius="23">
21                                 <ScrollViewer x:Name="PART_ContentHost" Margin="5,0"  VerticalAlignment="Center" Foreground="{TemplateBinding Foreground}" Background="{TemplateBinding Background}"/>
22                             </Border>
23                         </Border>
24                         <ControlTemplate.Triggers>
25                             <!--当鼠标移入输入框-->
26                             <Trigger Property="IsMouseOver" Value="True">
27                                 <Setter Property="BorderBrush" TargetName="Bd" Value="#FF66AFE9"/>
28                             </Trigger>
29                          <!--当输入框获得焦点-->
30                             <Trigger Property="IsFocused" Value="True">
31                                 <!--外边框阴影设置-->
32                                 <Setter Property="Effect" TargetName="Bd">
33                                     <Setter.Value>
34                                         <DropShadowEffect BlurRadius="10" Color="#FFE5F2FC" Direction="0" ShadowDepth="0"/>
35                                     </Setter.Value>
36                                 </Setter>
37                                 <Setter Property="BorderBrush" TargetName="Bd" Value="#FF66AFE9"/>
38                             </Trigger>
39                             
40                         </ControlTemplate.Triggers>
41                     </ControlTemplate>
42                 </Setter.Value>
43             </Setter>
44         </Style>
45 
46     </Window.Resources>
47     <StackPanel>
48         <TextBox Margin="10" Style="{StaticResource aa}"  FontSize="17" Height="50" Width="200"  Foreground="Black"/>
49         <TextBox Margin="10" Style="{StaticResource aa}"  FontSize="17" Height="50" Width="200"  Foreground="Black"/>
50 
51     </StackPanel>
View Code

样式

原文地址:https://www.cnblogs.com/lizhenlin/p/6021359.html