zoukankan      html  css  js  c++  java
  • 模板、触发器与动画

    <Window x:Class="WpfControlTemplateTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfControlTemplateTest"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
    <ResourceDictionary>
    <Style TargetType="Button">
    <Setter Property="Width" Value="100" />
    <Setter Property="Height" Value="40" />
    <Setter Property="Background" Value="LightGreen" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="Foreground" Value="White" />
    <!--利用样式属性指定模板-->
    <Setter Property="Template">
    <Setter.Value>
    <!--通过样式属性值来设置外观模板ControlTemplate-->
    <ControlTemplate TargetType="Button">
    <Grid>
    <Border CornerRadius="10" Background="LightGreen" />
    <!--常用属性通过控件修改-->
    <ContentPresenter
    Content="{TemplateBinding Content}"
    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
    Margin="{TemplateBinding Margin}"
    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
    />
    </Grid>
    <ControlTemplate.Triggers>
    <Trigger Property="IsMouseOver" Value="true">
    <Trigger.EnterActions>
    <BeginStoryboard>
    <Storyboard>
    <DoubleAnimation Storyboard.TargetProperty="Width" To="200" Duration="0:0:0.5" />
    </Storyboard>
    </BeginStoryboard>
    </Trigger.EnterActions>
    <Trigger.ExitActions>
    <BeginStoryboard>
    <Storyboard>
    <DoubleAnimation Storyboard.TargetProperty="Width" To="100" Duration="0:0:0.5" />
    </Storyboard>
    </BeginStoryboard>
    </Trigger.ExitActions>
    </Trigger>
    </ControlTemplate.Triggers>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>
    </ResourceDictionary>
    </Window.Resources>
    <Grid>
    <Button x:Name="btn1" Content="btn1" />
    <Rectangle x:Name="rt" Height="40" Width="10" Fill="Blue" HorizontalAlignment="Left" VerticalAlignment="Bottom" >
    <Rectangle.RenderTransform>
    <TranslateTransform x:Name="rtf" />
    </Rectangle.RenderTransform>
    </Rectangle>
    </Grid>
    </Window>

  • 相关阅读:
    修改Win7远程桌面端口【适用XP/2003】
    Mysql Select语句详情
    SqlServer之连接
    MySql数据类型分析(日期时间类型) Part5
    MySql数据类型分析(银行家舍入法) Part3
    MySql数据类型分析(数值(小数型)类型) Part2
    MySql数据类型分析(数值(整形)类型) Part1
    WP系统一次订阅,终身锁屏同时显示农历和天气
    c# 操作 XML(增 ,删 , 改 , 查)
    Postgresql 读取txt到DB 插入或更新
  • 原文地址:https://www.cnblogs.com/sundh1981/p/14343664.html
Copyright © 2011-2022 走看看