zoukankan      html  css  js  c++  java
  • WPF模板

    先来个模板:

    <ControlTemplate x:Key="button" TargetType="Button">
                <Border CornerRadius="4" BorderThickness="3">
                    <Border.BorderBrush>
                        <LinearGradientBrush EndPoint="0,1">
                            <GradientStop Offset="0" Color="#FF95EB09"/>
                            <GradientStop Offset="1" Color="Yellow"/>
                        </LinearGradientBrush>
                    </Border.BorderBrush>
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0,1">
                            <GradientStop Offset="0" Color="Yellow"/>
                            <GradientStop Offset="1" Color="#FF95EB09"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <ContentPresenter  HorizontalAlignment="Center"
                                       VerticalAlignment="Center"/>
                </Border>
                
            </ControlTemplate>

    注:边框与背景的渐变色相反可以显得有质感,

    效果如:

    1.模板绑定

      我们希望能够添加一些参数到模板中,或者利用来自模板控件中的属性更进一步地自定义控件,

    所以我们可以在模板控件上绑定属性,让控件使用者能够调整控件上的属性并自定义模板,代码如:

     <ControlTemplate x:Key="button" TargetType="{x:Type Button}">
                <Border CornerRadius="4" BorderThickness="{TemplateBinding Property=BorderThickness}"
                        BorderBrush="{TemplateBinding Property=BorderBrush}"
                        Background="{TemplateBinding Property=Background}"
                        >
                    <ContentPresenter/>
    
                </Border>
            </ControlTemplate>

      这段代码把来自Border的三个属性绑定到了模板化的Button控件上同样的属性上。这样做以后,只需简单

    的设置Button上的属性,就可以了创建下图的按钮:

     <ControlTemplate x:Key="button" TargetType="{x:Type Button}">
                <Border CornerRadius="4" BorderThickness="{TemplateBinding Property=BorderThickness}"
                        BorderBrush="{TemplateBinding Property=BorderBrush}"
                        Background="{TemplateBinding Property=Background}"
                        >
                    <ContentPresenter/>
    
                </Border>
            </ControlTemplate>

  • 相关阅读:
    Angular2版本更新
    Angular2组件开发—调用服务(三)
    Angular2组件开发—调用服务(二)
    Angular2组件开发—调用服务(一)
    Angular2组件开发—表单输入(五)
    Angular2组件开发—表单输入(四)
    Angular2组件开发—表单输入(三)
    Angular2组件开发—表单输入(二)
    Angular2组件开发—表单输入(一)
    Angular2组件开发—属性与事件(二)
  • 原文地址:https://www.cnblogs.com/smiler/p/3189394.html
Copyright © 2011-2022 走看看