zoukankan      html  css  js  c++  java
  • WPF控件模版

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

    imageimage

    01 <Window x:Class="DeepXAML.MainWindow"
    03         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    04         xmlns:local="clr-namespace:DeepXAML"       
    05         xmlns:sys="clr-namespace:System;assembly=mscorlib"
    06         Title="MainWindow" Height="250" Width="450">
    07     <Window.Resources>
    08         <Style x:Key="roundButton" TargetType="Button">
    09             <Setter Property="Background">
    10                 <Setter.Value>
    11                     <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
    12                         <LinearGradientBrush.GradientStops>
    13                             <GradientStop Offset="0.0" Color="#fff" />
    14                             <GradientStop Offset="1.0" Color="Red" />
    15                         </LinearGradientBrush.GradientStops>
    16                     </LinearGradientBrush>
    17                 </Setter.Value>
    18             </Setter>
    19             <Setter Property="Template">
    20                 <Setter.Value>
    21                     <ControlTemplate TargetType="Button">
    22                         <Grid>
    23                             <Ellipse Fill="{TemplateBinding Background}"></Ellipse>
    24                             <ContentPresenter Margin="5" HorizontalAlignment="Center" VerticalAlignment="Center" />                        </Grid>                   
    25                     </ControlTemplate>
    26                 </Setter.Value>
    27             </Setter>
    28         </Style>    
    29     </Window.Resources>
    30     <StackPanel x:Name="stackPanel">
    31         <Button Width="200" Height="120" Margin="20" Style="{StaticResource ResourceKey=roundButton}">OK</Button>
    32     </StackPanel>
    33 </Window>

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

  • 相关阅读:
    高性能网站优化——兼容
    高性能网站优化——开发
    leetcode刷题日记: 19.删除链表的倒数第k个节点
    大数据处理技术学习
    <java复习>返回可变对象引用的get方法要点
    <C++网络编程随笔>常用Socket函数总结
    <leetcode每日一题>数组中的第K个最大元素
    <leetcode每日一题>二叉树的LCA查找
    codeforce round615 div3 B
    暑假作业竟然如此芳香(hdu4145枚举+贪心)
  • 原文地址:https://www.cnblogs.com/luluping/p/2039508.html
Copyright © 2011-2022 走看看