博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Image Button example
阅读量:6642 次
发布时间:2019-06-25

本文共 1880 字,大约阅读时间需要 6 分钟。

Here's an example I made real quick to get you started. 

<Style TargetType="Button"

                x:Key="styleA">
            <Setter Property="Template">
               <Setter.Value>
                  <ControlTemplate TargetType="Button">
                     <Grid x:Name="RootElement"
                           Background="Transparent">
                        <Grid.Resources>
                           <Storyboard x:Key="MouseOver State">
                             
                              <DoubleAnimation Storyboard.TargetName="buttonScale"
                                               Storyboard.TargetProperty="ScaleX"
                                               To="1.2"
                                               Duration="00:00:00.25"/>
                              <DoubleAnimation Storyboard.TargetName="buttonScale"
                                               Storyboard.TargetProperty="ScaleY"
                                               To="1.2"
                                               Duration="00:00:00.25" />
                           </Storyboard>

                           <Storyboard x:Key="Normal State">

                              <DoubleAnimation Storyboard.TargetName="buttonScale"

                                               Storyboard.TargetProperty="ScaleX"
                                               To="1"
                                               Duration="00:00:00.25" />
                              <DoubleAnimation Storyboard.TargetName="buttonScale"
                                               Storyboard.TargetProperty="ScaleY"
                                               To="1"
                                               Duration="00:00:00.25" />
                           </Storyboard>
                          
                           <Storyboard x:Key="Pressed State">

                              <DoubleAnimation Storyboard.TargetName="buttonScale"

                                               Storyboard.TargetProperty="ScaleX"
                                               To="1.4"
                                               Duration="00:00:00.25" />
                              <DoubleAnimation Storyboard.TargetName="buttonScale"
                                               Storyboard.TargetProperty="ScaleY"
                                               To="1.4"
                                               Duration="00:00:00.25" />
                           </Storyboard>

                        </Grid.Resources>
                        <ContentPresenter Content="{TemplateBinding Content}"
                                          RenderTransformOrigin="0.5,0.5">
                           <ContentPresenter.RenderTransform>
                              <ScaleTransform x:Name="buttonScale" />
                           </ContentPresenter.RenderTransform>
                        </ContentPresenter>
                     </Grid>
                  </ControlTemplate>                 
               </Setter.Value>
              
            </Setter>
         </Style>

 You'll want to affect the content of the button to what you need, for example :

 <Button Width="100"

              x:Name="buttonTest"
              Style="{StaticResource styleA}"
              Click="buttonTest_Click">
         <StackPanel Orientation="Vertical">
            <Image Source="image1.jpg" />
            <TextBlock Text="Test 1" />
         </StackPanel>
      </Button>

Modify the storyboard states to reflect what you need for your RenderTransform etc...

 Hope this helps ! If it did, remember to mark the post as answered !

转载地址:http://uzovo.baihongyu.com/

你可能感兴趣的文章
centos 7 安装MySql
查看>>
LeetCode: Adding two numbers (by list)
查看>>
Hibernate查询 内连接和外连接区别
查看>>
1068. [SCOI2007]压缩【区间DP】
查看>>
下载远程(第三方服务器)文件、图片,保存到本地(服务器)的方法、保存抓取远程文件、图片...
查看>>
Docker四种网络模式
查看>>
c:url标签
查看>>
Silverlight-Validation服务器端异步数据验证
查看>>
最新VIN(车辆识别码)解析
查看>>
ubuntu下出现的问题-控制台更新源失败
查看>>
获得user account的SID,GUID
查看>>
SkyLine二次开发——解决在web页面启动时自动运行TerraExplorer的问题
查看>>
[转载]我们可以用SharePoint做什么
查看>>
ubuntu 16.04 安装Opencv-3.2.0_GPU 与 opencv_contrib-3.2.0
查看>>
ldap信息交互未完成
查看>>
输出word EXCEL xml html处理---H_print.php
查看>>
【python】安装Python 的IDE--PyCharm
查看>>
【js 方法】js 页面刷新location.reload和location.replace的区别 【转】
查看>>
一个单元测试 学习 aysnc await
查看>>
intellij 创建java web项目(maven管理的SSH)
查看>>