WPF styling and templating are a set of features (styles, templates, triggers, and presentation plates) that set a uniform appearance for your product. HTML-like CSS, you can quickly set a series of property values to the control.
Case: ButtonStyle
This creates a basic buttonstyle with a target type of button, the other button can inherit systembuttonbase, can unify the base style, set the desired property value according to the requirement, The login button can be used to find this style using the StaticResource method.
1 <Stylex: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>Ten <ControlTemplateTargetType="{x:type ButtonBase}"> One <BorderName= "Chrome" A Background="{TemplateBinding Background}" - borderthickness="{TemplateBinding BorderThickness}" - BorderBrush="{TemplateBinding BorderBrush}" the Snapstodevicepixels= "true" - Cornerradius= "5"> - <ContentPresenterMargin="{TemplateBinding Padding}" - VerticalAlignment="{TemplateBinding Verticalcontentalignment}" + HorizontalAlignment="{TemplateBinding Horizontalcontentalignment}" - Recognizesaccesskey= "True" + Snapstodevicepixels="{TemplateBinding Snapstodevicepixels}"/> A </Border> at </ControlTemplate> - </Setter.value> - </Setter> - <style.triggers> - <Trigger Property= "IsEnabled"Value= "false"> - <Setter Property= "Cursor"Value= "Arrow" /> in </Trigger> - </style.triggers> to </Style> + <StyleTargetType= "button"BasedOn="{StaticResource Systembuttonbase}"x:key= "Btnstyle"> - <Setter Property= "Background"Value= "#09a3dc"/> the <Setter Property= "Foreground"Value= "#ffffff"/> * <Setter Property= "MinHeight"Value= "+"/> $ <Setter Property= "MinWidth"Value= "The "/>Panax Notoginseng <style.triggers> - <Trigger Property= "IsMouseOver"Value= "True"> the <Setter Property= "Background"Value= "#3cc3f5"/> + </Trigger> A <Trigger Property= "IsPressed"Value= "True"> the <Setter Property= "Background"Value= "#098cbc" /> + </Trigger> - <Trigger Property= "IsEnabled"Value= "false"> $ <Setter Property= "Background"Value= "#e1e1e1" /> $ <Setter Property= "Foreground"Value= "#7e7e7e" /> - </Trigger> - </style.triggers> the </Style>
Simple reference
1 <button content=" login " height= "margin=" 0" width= " "style="{ StaticResource Btnstyle}"/>
This is the short text of the presentation of the WPF style
Hope and we have a lot of communication and common progress. Thank you!
WPF style settings and templating template