WPF复杂形状按钮
方法很简单,将图片转换为<path>就可以了(需要用到Photoshop)
不过一般情况下制作按钮都不会用到这种方法,通常只要用image填充一张图片或者把路径转成按钮控件就可以了。
之所以这样做,是见到一位坛友提问说:如何根据PNG图片的形状来决定按钮的形状,大概意思可能就是只有在PNG
图像形状范围内触发器才有效,不过他说的我也没怎么听明白,呵呵。。。自己试着做了一下。目前就想到了这个方法,也许还有更好的方法!
Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Path x:Name="形状_1" Data="M 32.9626,1.52588e-005C 64.8366,-1.05113 86.9761,13.3906 90.2887,40.0549C 121.366,22.922 167.447,36.5059 190.609,52.9298C 196.819,60.0817 203.031,67.2358 209.24,74.3877C 218.587,80.7901 229.685,81.6765 236.47,90.1236C 238.66,92.8495 248.286,130.997 249.369,135.901C 258.248,176.097 225.629,230.492 199.208,228.885C 210.609,245.719 247.47,243.846 260.834,260.357C 258.446,264.648 256.057,268.941 253.668,273.232C 254.624,273.232 255.579,273.232 256.535,273.232C 266.144,278.475 277.516,274.548 286.631,271.801C 286.631,278 286.631,284.2 286.631,290.398C 270.758,292.489 258.952,283.729 243.636,286.107C 231.045,288.061 212.93,298.373 196.342,291.829C 187.923,288.507 176.727,274.685 167.679,268.94C 169.112,257.974 170.545,247.004 171.978,236.038C 171.501,236.038 171.023,236.038 170.545,236.038C 158.23,240.139 147.846,241.445 150.481,257.496C 153.347,257.973 156.214,258.45 159.08,258.927C 157.574,270.027 155.171,292.206 163.38,301.843C 167.201,303.75 171.023,305.658 174.845,307.565C 178.188,315.194 181.533,322.825 184.877,330.453C 196.377,340.356 212.387,340.294 222.139,351.911C 148.1,351.911 74.0389,351.911 0,351.911C 2.38837,349.05 4.77742,346.189 7.16574,343.328C 26.8224,334.338 23.7874,310.676 37.262,296.12C 45.8601,298.028 54.4607,299.935 63.0588,301.843C 63.5364,300.412 64.0143,298.981 64.4919,297.551C 62.1036,285.154 59.7145,272.754 57.3262,260.357C 56.8485,260.357 56.3707,260.357 55.893,260.357C 55.893,267.986 55.893,275.617 55.893,283.246C 55.4153,283.246 54.9375,283.246 54.4599,283.246C 54.4599,282.292 54.4599,281.338 54.4599,280.385C 48.716,268.591 52.2378,254.85 53.0267,240.33C 42.9823,238.522 30.6873,236.171 25.7968,228.885C 20.3403,219.725 16.4283,166.867 14.3315,155.928C 25.3332,155.55 33.2694,151.907 37.262,144.484C 42.9325,134.876 41.5233,110.573 44.4278,98.7068C 43.4724,99.1836 42.5168,99.6605 41.5615,100.137C 36.665,114.747 29.8112,126.853 25.7968,144.484C 25.3191,144.484 24.8413,144.484 24.3636,144.484C 20.4211,118.72 25.9583,98.0166 34.3957,81.5404C 21.5746,91.6128 18.1252,106.513 10.0321,121.595C 9.55441,121.595 9.0766,121.595 8.59889,121.595C 8.59889,121.119 8.59889,120.642 8.59889,120.165C 18.9555,78.4881 36.1168,33.5594 88.8555,41.4855C 82.3319,4.01784 40.9382,1.40187 8.59889,12.8748C 9.55426,11.4444 10.5099,10.0137 11.4652,8.58327C 18.6303,5.72243 25.7975,2.86086 32.9626,1.52588e-005 Z " Stretch="Fill" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Path.RenderTransform>
<Path.Effect>
<DropShadowEffect ShadowDepth="" BlurRadius="" Color="#FF646464"/>
</Path.Effect>
<Path.Fill>
<ImageBrush ImageSource="图层 1.png"/>
</Path.Fill>
</Path>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content=""/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="RenderTransform" TargetName="形状_1">
<Setter.Value>
<TransformGroup>
<ScaleTransform ScaleX="1.01" ScaleY="1.01"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Effect" TargetName="形状_1">
<Setter.Value>
<DropShadowEffect BlurRadius="" Color="Red" ShadowDepth=""/>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
转载:http://blog.csdn.net/cmis7645/article/details/7592372
WPF复杂形状按钮的更多相关文章
- WPF解决按钮上被透明控件遮盖时无法点击问题
原文:WPF解决按钮上被透明控件遮盖时无法点击问题 IsHitTestVisible="False" 在控件上设置如上属性即可,即可让透明控件不触发点击效果
- [C# WPF] 根据按钮动态跳转窗体
WPF 根据按钮动态跳转窗体 XMAL文件中,用Tag保存要跳的页面 <Button Name="btnWindow01" Content="ClickMe&quo ...
- 写自己的WPF样式 - 按钮
做一个后台管理小程序,据说WPF的界面比较"炫",于是选择使用WPF来开发.既然用了WPF当然需要做好看点了,于是稍微研究了下WPF的样式,废话不多说下面开始自定义一个按钮样式: ...
- WPF界面按钮美化
在App.xaml里加入全局按钮样式 <Application x:Class="WpfButton.App" xmlns="http://schemas.micr ...
- WPF -- 自定义按钮
本文介绍WPF一种自定义按钮的方法. 实现效果 使用图片做按钮背景: 自定义鼠标进入时效果: 自定义按压效果: 自定义禁用效果 实现效果如下图所示: 实现步骤 创建CustomButton.cs,继承 ...
- WPF实现按钮鼠标停留样式的一个坑
弄了个按钮鼠标停留样式,发现把它应用到某些窗体的Button上会发生样式模糊的问题,而其它窗体又不会. 百思不得其解,真是活久见. 后来发现是跟包着Button的容器控件有关,只要是那些会自适应的容器 ...
- WPF圆角按钮与触发颜色变化
<Button x:Name="button1" Content="按钮1" Margin="10,10,0,0" Cursor=&q ...
- WPF圆角按钮例程
<Window x:Class="WpfApp3.MainWindow" xmlns="http://schemas.microsoft.com/winfx/200 ...
- 如何给wpf的按钮添加背景图片
1:简单实用 <Button Height="143" HorizontalAlignment="Left" Margin="30,34,0,0 ...
随机推荐
- Delphi 无类型文件
- openxlsx模块
import openpyxl #创建工作簿 wb = openpyxl.Workbook()#获取当前活跃的工作表 ws = wb.active#删除工作表 remove_sheet(wb.get_ ...
- uft 测试工具使用
选择 uft 自带小飞机 cs测试 开始设置 启动插件管理 选择测试 软件类型 cs bs 新建录制项目 各个功能按钮 添加测试程序工作路径 进入录制 保存录制 ...
- docker_Ubuntu16.04下安装cuda
经过一上午的研究,终于配置好docker环境,并成功安装cuda9.0. (1)下载安装文件.首先去英伟达官网下载cuda安装包:https://developer.nvidia.com/cuda-t ...
- 实践:Linux用户、组和密码相关文件被破坏如何恢复系统
我们先看一下用户用户组和密码相关文件: 1 2 3 4 5 6 7 8 9 [root❄centos7 ~]☭ ll /etc/passwd* /etc/shadow* /etc/group* /et ...
- 前端form表单与css
form表单(******) 能够获取用户输入(输入,选择,上传的文件) 并且将用户输入的内容全部发送给后端 参数 action 控制数据提交的地址 三种书写方式 1.不写 默认就是朝当前这个页面所在 ...
- DevExpress ASP.NET Core v19.1版本亮点:Rich Text Editor
行业领先的.NET界面控件DevExpress 发布了v19.1版本,本文将以系列文章的方式为大家介绍DevExpress ASP.NET Core Controls v19.1中新增的一些控件及增强 ...
- Mac的MySQL无法启动的原因
一.由于Mac OS X的升级或其他原因可能会导致一个错误: Warning:The /usr/local/mysql/data directory is not owned by the 'mysq ...
- params修饰符的用法
params修饰符是用来声明参数数组允许向方法传递数量不定的自变量用的.事实上System.Console 类的 Write 和 WriteLine 方法是参数数组用法的典型示例.他们的声明方式如下: ...
- 基于Python原生asyncio模块对DNS正向和反向的解析
一.正向解析:域名解析IP地址 import asyncio import socket domains = [ ('www.baidu.com', 'https'), ('cn.bing.com', ...