WPF style and behavior, WPF style Behavior

Source: Internet
Author: User

WPF style and behavior, WPF style Behavior

 


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 style problems

Is the original template changed in the style of this button? If you change the content, you need a ContentPresenter to define the content. Otherwise, you cannot set the content. The following is an example.
<Style TargetType = "Button">
<Setter Property = "Template">
<Setter. Value>
<ControlTemplate TargetType = "Button">
<Border x: Name = "back">
<ContentPresenter x: Name = "content" HorizontalAlignment = "Center" verticalignment = "Center" Content = "{TemplateBinding Content}">
</ContentPresenter>
</Border>
</ControlTemplate>
</Setter. Value>
</Setter>
</Style>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.