Silverlight templates (template) use

Source: Internet
Author: User
Tags silverlight

A template is another style of control that differs from the style (style) in that it allows existing controls to combine a new control style

So first look at the simplest template code

XAML Code

<button content="Button"height=" at"Horizontalalignment=" Left"Margin="44,30,0,0"Name="button1"Verticalalignment="Top"Width=" the"> <Button.Template> <ControlTemplate> <border Borderthickne ss="3"Borderbrush="#FF6969FF"> <Border.Background> <lineargradientbrush endpoint="0.5,1"Startpoint="0.5,0"> <gradientstop color="#FF6F97FF"offset="0"/> <gradientstop color="#FF0021FF"offset="0.574"/> <gradientstop color="#FF6C7BFF"offset="1"/> </LinearGradientBrush> </Border.Background> <textblock text="Button"Horizontalalignment="Center"VerticalAlignment="Center"Foreground="Lime"></TextBlock> </Border> </ControlTemplate> </Button.Template> </Button>

  

That's a little more complicated

<controltemplate x:key="TPE"> <border borderthickness="3"Borderbrush="#FF6969FF"> <Border.Background> <lineargradientbrush endpoint="0.5,1"Startpoint="0.5,0"> <gradientstop color="#FF6F97FF"offset="0"/> <gradientstop color="#FF0021FF"offset="0.574"/> <gradientstop color="#FF6C7BFF"offset="1"/> </LinearGradientBrush> </Border.Background> &LT;CONTENTPR Esenter verticalalignment="{TemplateBinding VerticalAlignment}"HorizontalAlignment="Center"></ContentPresenter> </Border> </ControlTemplate> <button content="Button"Template="{StaticResource TPE}"height=" at"HorizontalAlignment=" Left"margin="44,30,0,0"Name="button1"VerticalAlignment="Top"Width=" the">

  

ContentPresenter represents a mapping method for the content property of a button

So the purple code has a templatebinding. It indicates that the value of the verticalalignment that specifies a correlation property mapping Map button can also be margin mapped padding because they are two compatible

In style you can use template

XAML Code

<style x:key="S1"Targettype="Button"> <setter property="Template"Value="{StaticResource TPE}"></Setter> </Style> <button content="Button"style="{StaticResource S1}"height=" at"HorizontalAlignment=" Left"margin="44,30,0,0"Name="button1"VerticalAlignment="Top"Width=" the">

However, if you set the value of a property in the style, the value of the TemplateBinding mapping for the template does not map on the control.

Silverlight templates (template) use

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.