zoukankan      html  css  js  c++  java
  • 无废话WPF系列18:控件模版

    控件模版ControlTemplate就是设置控件的外观,比如我们常见到的按钮是下面这样的,但是我们如何改变成圆形的呢?

    imageimage

    <Window x:Class="DeepXAML.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:DeepXAML"       
            xmlns:sys="clr-namespace:System;assembly=mscorlib"
            Title="MainWindow" Height="250" Width="450">
        <Window.Resources>
            <Style x:Key="roundButton" TargetType="Button">
                <Setter Property="Background">
                    <Setter.Value>
                        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                            <LinearGradientBrush.GradientStops>
                                <GradientStop Offset="0.0" Color="#fff" />
                                <GradientStop Offset="1.0" Color="Red" />
                            </LinearGradientBrush.GradientStops>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Grid>
                                <Ellipse Fill="{TemplateBinding Background}"></Ellipse>
                                <ContentPresenter Margin="5" HorizontalAlignment="Center" VerticalAlignment="Center" />                        </Grid>                   
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>    
        </Window.Resources>
        <StackPanel x:Name="stackPanel">
            <Button Width="200" Height="120" Margin="20" Style="{StaticResource ResourceKey=roundButton}">OK</Button>
        </StackPanel>
    </Window>

    ItemsControl有个PanelTemplate可以控制ItemsControl的条目容器。

  • 相关阅读:
    只允许在input框输入文字,不能输入数字和其他字符
    阻止用户在input框输入数字
    centos 7.2安装和配置MongoDB
    Python基础
    Python小练习008
    Python小练习007
    Python小练习006
    Python错误集锦
    Python和MongoDB
    MongoDB笔记
  • 原文地址:https://www.cnblogs.com/cnblogsfans/p/1966176.html
Copyright © 2011-2022 走看看