ControlTemple样式

时间:2023-03-09 00:46:23
ControlTemple样式

1.TextBox 样式

1.1 style

    <Window.Resources>
<Style x:Key="aa" TargetType="{x:Type TextBox}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderThickness" Value=""/>
<Setter Property="Padding" Value=""/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<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="Bd" CornerRadius="" Padding="" BorderBrush="#FFDDDDDD" BorderThickness="" >
<Border.Effect>
<DropShadowEffect BlurRadius="" Color="#FFE5F2FC" Direction="" ShadowDepth=""/>
</Border.Effect>
<!--这个Border主要用来遮挡框内的阴影,只要外阴影,如果只要内阴影不要外阴影,那么设置border的 ClipToBounds="True" 剪切外部内容,即可实现内阴影-->
<Border Background="White" CornerRadius="">
<ScrollViewer x:Name="PART_ContentHost" Margin="5,0" VerticalAlignment="Center" Foreground="{TemplateBinding Foreground}" Background="{TemplateBinding Background}"/>
</Border>
</Border>
<ControlTemplate.Triggers>
<!--当鼠标移入输入框-->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="Bd" Value="#FF66AFE9"/>
</Trigger>
<!--当输入框获得焦点-->
<Trigger Property="IsFocused" Value="True">
<!--外边框阴影设置-->
<Setter Property="Effect" TargetName="Bd">
<Setter.Value>
<DropShadowEffect BlurRadius="" Color="#FFE5F2FC" Direction="" ShadowDepth=""/>
</Setter.Value>
</Setter>
<Setter Property="BorderBrush" TargetName="Bd" Value="#FF66AFE9"/>
</Trigger> </ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> </Window.Resources>
<StackPanel>
<TextBox Margin="" Style="{StaticResource aa}" FontSize="" Height="" Width="" Foreground="Black"/>
<TextBox Margin="" Style="{StaticResource aa}" FontSize="" Height="" Width="" Foreground="Black"/> </StackPanel>

样式