动态按钮

实现功能 :当鼠标移上去的时候按钮变大,离开的时候恢复。

  1 <Window
  2     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4     x:Class="WPFtest.Window1"
  5     x:Name="Window"
  6     Title="Window1"
  7     Width="640" Height="480">
  8     <Window.Resources>
  9         <Color x:Key="Color1">#FFEBD3D3</Color>
 10         <Style x:Key="ButtonStyle1" BasedOn="{x:Null}" TargetType="{x:Type Button}">
 11             <Setter Property="Template">
 12                 <Setter.Value>
 13                     <ControlTemplate TargetType="{x:Type Button}">
 14                         <Grid>
 15                             <Rectangle RenderTransformOrigin="0.5,0.5" Stroke="#FF000000" RadiusX="18.5" RadiusY="18.5">
 16                                 <Rectangle.RenderTransform>
 17                                     <TransformGroup>
 18                                         <ScaleTransform ScaleX="1" ScaleY="1"/>
 19                                         <SkewTransform AngleX="0" AngleY="0"/>
 20                                         <RotateTransform Angle="-0.019"/>
 21                                         <TranslateTransform X="0" Y="0"/>
 22                                     </TransformGroup>
 23                                 </Rectangle.RenderTransform>
 24                                 <Rectangle.Fill>
 25                                     <LinearGradientBrush SpreadMethod="Pad" EndPoint="0.5,1" StartPoint="0.5,0">
 26                                         <GradientStop Color="#FF000000" Offset="0"/>
 27                                         <GradientStop Color="{DynamicResource Color1}" Offset="1"/>
 28                                     </LinearGradientBrush>
 29                                 </Rectangle.Fill>
 30                             </Rectangle>
 31                             <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True"/>
 32                         </Grid>
 33                         <ControlTemplate.Triggers>
 34                             <Trigger Property="IsFocused" Value="True"/>
 35                             <Trigger Property="IsDefaulted" Value="True"/>
 36                             <Trigger Property="IsMouseOver" Value="True"/>
 37                             <Trigger Property="IsPressed" Value="True"/>
 38                             <Trigger Property="IsEnabled" Value="False"/>
 39                         </ControlTemplate.Triggers>
 40                     </ControlTemplate>
 41                 </Setter.Value>
 42             </Setter>
 43         </Style>
 44         <Storyboard x:Key="Storyboard1">
 45             <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
 46                 <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
 47                 <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1.725"/>
 48             </DoubleAnimationUsingKeyFrames>
 49             <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
 50                 <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
 51                 <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1.725"/>
 52             </DoubleAnimationUsingKeyFrames>
 53             <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
 54                 <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
 55                 <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1.875"/>
 56             </DoubleAnimationUsingKeyFrames>
 57             <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
 58                 <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
 59                 <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="-0.5"/>
 60             </DoubleAnimationUsingKeyFrames>
 61         </Storyboard>
 62         <Storyboard x:Key="Storyboard2">
 63             <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="button">
 64                 <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1.725"/>
 65                 <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1"/>
 66             </DoubleAnimationUsingKeyFrames>
 67             <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="button">
 68                 <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1.725"/>
 69                 <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1"/>
 70             </DoubleAnimationUsingKeyFrames>
 71             <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="button">
 72                 <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1.875"/>
 73                 <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
 74             </DoubleAnimationUsingKeyFrames>
 75             <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="button">
 76                 <SplineDoubleKeyFrame KeyTime="00:00:00" Value="-0.5"/>
 77                 <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
 78             </DoubleAnimationUsingKeyFrames>
 79         </Storyboard>
 80     </Window.Resources>
 81     <Window.Triggers>
 82         <EventTrigger RoutedEvent="FrameworkElement.Loaded"/>
 83         <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="button">
 84             <BeginStoryboard Storyboard="{StaticResource Storyboard1}" x:Name="Storyboard1_BeginStoryboard"/>
 85         </EventTrigger>
 86         <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="button">
 87             <BeginStoryboard Storyboard="{StaticResource Storyboard2}" x:Name="Storyboard2_BeginStoryboard"/>
 88         </EventTrigger>
 89     </Window.Triggers>
 90
 91     <Grid x:Name="LayoutRoot">
 92         <Button HorizontalAlignment="Left" Margin="82,63,0,0" Style="{DynamicResource ButtonStyle1}" VerticalAlignment="Top" Width="110" Height="40" Content="按钮" Foreground="#FFF9F6F9" x:Name="button" RenderTransformOrigin="0.5,0.5">
 93             <Button.RenderTransform>
 94                 <TransformGroup>
 95                     <ScaleTransform ScaleX="1" ScaleY="1"/>
 96                     <SkewTransform AngleX="0" AngleY="0"/>
 97                     <RotateTransform Angle="0"/>
 98                     <TranslateTransform X="0" Y="0"/>
 99                 </TransformGroup>
100             </Button.RenderTransform>
101         </Button>
102     </Grid>
103 </Window>
时间: 2024-10-03 23:00:47

动态按钮的相关文章

MFC动态按钮的创建及其消息响应(自定义消息)

动态按钮(多个)的创建: 1.在类中声明并定义按钮控件的ID #define IDC_D_BTN 10000 2.在类的OnInitDialog()函数中动态创建按钮(建立按钮对象时最好建立对象的指针) 3.手动释放对象指针 下面是动态生成多个按钮的例子: CButton* btn = new CButton[5]; DWORD dwStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON; for(int i = 0; i < 5; i++) { btn[i]

MFC动态按钮的创建及其消息响应 和 自定义消息

原文链接: http://www.cnblogs.com/gaohongchen01/p/4046525.html 动态按钮(多个)的创建: 1.在类中声明并定义按钮控件的ID #define IDC_D_BTN 10000 2.在类的OnInitDialog()函数中动态创建按钮(建立按钮对象时最好建立对象的指针) 3.手动释放对象指针 下面是动态生成多个按钮的例子: CButton* btn = new CButton[5]; DWORD dwStyle = WS_CHILD | WS_VI

vue之小小动态按钮

Vue是前台框架,可以独立完成前后端分离式web项目渐进式的javascript框架 ,今天我们来设计一个简单的动态按钮 具体效果图如下: 点击后会变成这样: 首先我们需要下载vue.js:https://vuejs.org/js/vue.min.js 将网页内的内容全选粘贴至js文件中 然后我们先创建一个html文件 在body创建一个按钮具体代码如下: <body> <div id="app"> <button v-on:click="btn

模拟展示动态按钮

动态展示按钮    没有运行出效果来 package com.lsw.server; import java.applet.Applet; import java.awt.Button; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class

swift po 实现动态按钮2

// //  ButtonViewController.swift //  PopInstall // //  Created by su on 15/12/11. //  Copyright © 2015年 tian. All rights reserved. // import UIKit class ButtonViewController: UIViewController {    //状态     var hamburgerOpen = true    var hambureButt

Atitit 动态按钮图片背景颜色与文字组合解决方案

转换背景颜色,setFont("cywe_img", fontScale, 50, 5) 设置文字大小与坐标 文字分拆,使用字根组合,也就256个字根就够了. public static void main(String[] args) throws FileNotFoundException { long startTime = System.currentTimeMillis(); // 获取开始时间 String out = "C:\\0workspace\\AtiPl

MFC动态创建控件(按钮)及添加消息响应

动态控件是指在需要时由Create()创建的控件,这与预先在对话框中放置的控件是不同的. 一.创建动态控件: 为了对照,我们先来看一下静态控件的创建. 放置静态控件时必须先建立一个容器,一般是对话框,这时我们在对话框编辑窗口中,从工具窗口中拖出所需控件放在对话框中即可,再适当修改控件ID,设置控件属性,一个静态控件就创建好了,当对话框被显示时,其上的控件也会显示. 静态控件不需要调用Create()函数来创建. 而创建动态控件有很大不同,以下以按钮为例,看一下动态控件的创建过程: 1.建立控件I

动态添加按钮

1. 新建iOS -> Single View Application. 2. 个性控制器文件YYViewController.m(此处修改为你相应的控制器文件名) 1 // 2 // YYViewController.m 3 // StudyDynamicButton 4 // 5 // Created by yao_yu on 14-5-27. 6 // Copyright (c) 2014年 yao_yu. All rights reserved. 7 // 8 9 #import "

iOS 动态添加按钮

单击一个已有的按钮后自动创建一个新的按钮,并为新按钮添加事件,使得单击时弹出提示框. 在viewcontroller.h中添加 @property (weak, nonatomic) IBOutlet UIButton *addbutton; 为这个按钮添加响应事件addbutton 在viewcontroller.m中添加 - (IBAction)addButton:(id)sender { //动态添加一个按钮 CGRect frame = CGRectMake(0, 0, 300, 50)