WPF Template, wpftemplate
ControlTemplate
DataTemplate
Different styles and templates in WPF
Simply put, if you only need to slightly modify the control (adjust the size, position, Font, color, etc.), you can use the style, if you need to change the appearance and behavior of the control, use controlTemplate (shape, event triggering, such as mouse stop effect, etc ). In actual projects, we often define templates in styles by setting styles.
For example, if I want to create an image button for scaling a map, adjust the position using the style and use controltemplate to set the button shape.
<UserControl. Resources>
<Style x: Key = "ZoomUpButton" TargetType = "Button">
<Setter Property = "Width" Value = "23.5"/>
<Setter Property = "Height" Value = "25.5"/>
<Setter Property = "Template">
<Setter. Value>
<ControlTemplate TargetType = "Button">
<Grid Width = "23.5" Height = "25.5">
<Image Source = "/Resource/zoom=.png" Stretch = "Fill"/>
<ContentPresenter HorizontalAlignment = "Center"/>
</Grid>
<ControlTemplate. Triggers>
<Trigger Property = "IsMouseOver" Value = "True">
<Setter Property = "Effect">
<Setter. Value>
<DropShadowEffect ShadowDepth = "2"/>
</Setter. Value>
</Setter>
... The remaining full text>
Wpf uses a template to change the style of a space
<Menu Background = "White">
<Menu. Resources>
<ControlTemplate x: Key = "MenuItemTemplate" TargetType = "{x: Type MenuItem}">
<Grid>
<Ellipse Width = "{TemplateBinding MenuItem. Width}" Height = "{TemplateBinding MenuItem. Height}">
<Ellipse. Fill>
<LinearGradientBrush StartPoint = "0, 0" EndPoint = "0, 1">
<GradientStop Offset = "0"/>
<GradientStop Offset = "1" Color = "Gray"/>
</LinearGradientBrush>
</Ellipse. Fill>
</Ellipse>
<Viewbox>
<ContentControl Margin = "10"/>
</Viewbox>
<Ellipse Width = "30" Height = "17">
<Ellipse. Fill>
<LinearGradientBrush StartPoint = "0, 0" EndPoint = "0, 1
<GradientStop Offset = "0" Color = "White"/>
<GradientStop Offset = "1" Color = "Transparent & qu ...... the remaining full text>