WPF Style setting and templated Template, wpftemplate
WPF style settings and templatification are a set of functions (style, template, trigger, and demo version) that can set a unified appearance for the product. Similar to html css, you can quickly set a series of attribute values to controls.
Case: ButtonStyle
Here, a basic ButtonStyle with the target type of Button is created. Other buttons can inherit the SystemButtonBase, unify the basic Style, and set the required attribute values as needed, you can use StaticResource to find the style.
1 <Style x:Key="SystemButtonBase" TargetType="ButtonBase"> 2 <Setter Property="Background" Value="Transparent"/> 3 <Setter Property="BorderThickness" Value="0"/> 4 <Setter Property="HorizontalContentAlignment" Value="Center"/> 5 <Setter Property="VerticalContentAlignment" Value="Center"/> 6 <Setter Property="Cursor" Value="Hand"/> 7 <Setter Property="Padding" Value="1"/> 8 <Setter Property="Template"> 9 <Setter.Value>10 <ControlTemplate TargetType="{x:Type ButtonBase}">11 <Border Name="Chrome"12 Background="{TemplateBinding Background}"13 BorderThickness="{TemplateBinding BorderThickness}"14 BorderBrush="{TemplateBinding BorderBrush}"15 SnapsToDevicePixels="true"16 CornerRadius="5">17 <ContentPresenter Margin="{TemplateBinding Padding}"18 VerticalAlignment="{TemplateBinding VerticalContentAlignment}"19 HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"20 RecognizesAccessKey="True"21 SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>22 </Border>23 </ControlTemplate>24 </Setter.Value>25 </Setter>26 <Style.Triggers>27 <Trigger Property="IsEnabled" Value="false">28 <Setter Property="Cursor" Value="Arrow" />29 </Trigger>30 </Style.Triggers>31 </Style>32 <Style TargetType="Button" BasedOn="{StaticResource SystemButtonBase}" x:Key="BtnStyle">33 <Setter Property="Background" Value="#09a3dc"/>34 <Setter Property="Foreground" Value="#ffffff"/>35 <Setter Property="MinHeight" Value="28"/>36 <Setter Property="MinWidth" Value="70"/>37 <Style.Triggers>38 <Trigger Property="IsMouseOver" Value="True">39 <Setter Property="Background" Value="#3cc3f5"/>40 </Trigger>41 <Trigger Property="IsPressed" Value="True">42 <Setter Property="Background" Value="#098cbc" />43 </Trigger>44 <Trigger Property="IsEnabled" Value="false">45 <Setter Property="Background" Value="#e1e1e1" />46 <Setter Property="Foreground" Value="#7e7e7e" />47 </Trigger>48 </Style.Triggers>49 </Style>
Simple reference
1 <Button Content = "login" Height = "30" Margin = "0" Width = "115" Style = "{StaticResource BtnStyle}"/>
This is the brief text of the WPF Style.
I hope to communicate with you a lot and make progress together. Thank you!