运行环境:blend 4.0或者3.0
按钮不管是桌面应用软件还是网页,都是所用最多的控件,而一个好的设计构思,可以给用户带来很强悍的用户体验,现今,用户体验和用户交互设计得到了很大程度的重视,今天我模仿做了个对话框按钮。
源图片如右图所示:
我模仿的图片如右图所示:
很多不足尚待完善,不过如果作为一个程序员,一些东西从实践会慢慢领悟的
用blend的布局设计如下图所示:
相应的xaml代码如下所示:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<UserControl
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" mc:Ignorable="d"
x:Class="XamlDemo1.MainPage"
Width="640" Height="480">
<UserControl.Resources>
<Style x:Key="ButtonStyle1" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Border BorderThickness="1" CornerRadius="20,0,0,20">
<Path Data="M14.25,14 L29.782225,14" Margin="11,12,4.468,13.75" Stretch="Fill" UseLayoutRounding="False" Stroke="#FFFDFDFD" StrokeThickness="5"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ButtonStyle2" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Border BorderThickness="1">
<Grid Margin="8,11,11,9">
<Rectangle Stroke="#FFFDFDFD" Margin="3,-4,-3,4" StrokeThickness="2"/>
<Rectangle Stroke="#FFFDFDFD" StrokeThickness="2"/>
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ButtonStyle3" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Border BorderThickness="1" CornerRadius="0,20,20,0">
<Grid Margin="3,7,13,7">
<Path Data="M22.333344,8 L9.4470797,20.886263" Stretch="Fill" Stroke="#FFFDFDFD" StrokeThickness="3" UseLayoutRounding="False"/>
<Path Data="M0,0 L14.834265,14.834265" Stretch="Fill" Stroke="#FFFDFDFD" StrokeThickness="3" UseLayoutRounding="False"/>
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<Grid Height="30" Margin="267,192,241,0" VerticalAlignment="Top">
<Rectangle Margin="0,0,32,0" RadiusY="20" RadiusX="20" Stroke="#68000000" Fill="#FF372F2F"/>
<Button Content="Button" HorizontalAlignment="Left" Style="{StaticResource ButtonStyle1}" Width="34"/>
<Path Data="M33.5,0 L33.5,30.004166" HorizontalAlignment="Left" Margin="33.5,0.479,0,0.482" Stretch="Fill" UseLayoutRounding="False" Width="1">
<Path.Stroke>
<LinearGradientBrush EndPoint="4.189,0.313" StartPoint="-6.592,0.305">
<GradientStop Color="Black" Offset="0.485"/>
<GradientStop Color="#FFBEAFAF" Offset="0.714"/>
</LinearGradientBrush>
</Path.Stroke>
</Path>
<Path Data="M33.5,0 L33.5,30.004166" HorizontalAlignment="Left" Margin="34.5,0.479,0,0.482" Stretch="Fill" UseLayoutRounding="False" Width="1">
<Path.Stroke>
<LinearGradientBrush EndPoint="4.941,0.405" StartPoint="-7.687,0.405">
<GradientStop Color="Black" Offset="0.651"/>
<GradientStop Color="#FFBEAFAF" Offset="0.556"/>
</LinearGradientBrush>
</Path.Stroke>
</Path>
<Button Content="Button" HorizontalAlignment="Left" Margin="35,0,0,0" Style="{StaticResource ButtonStyle2}" Width="30"/>
<Path Data="M33.5,0 L33.5,30.004166" HorizontalAlignment="Left" Margin="65,0.961,0,0" Stretch="Fill" UseLayoutRounding="False" Width="1">
<Path.Stroke>
<LinearGradientBrush EndPoint="4.189,0.313" StartPoint="-6.592,0.305">
<GradientStop Color="Black" Offset="0.485"/>
<GradientStop Color="#FFBEAFAF" Offset="0.714"/>
</LinearGradientBrush>
</Path.Stroke>
</Path>
<Path Data="M33.5,0 L33.5,30.004166" HorizontalAlignment="Right" Margin="0,0.961,65,0" Stretch="Fill" UseLayoutRounding="False" Width="1">
<Path.Stroke>
<LinearGradientBrush EndPoint="4.941,0.405" StartPoint="-7.687,0.405">
<GradientStop Color="Black" Offset="0.651"/>
<GradientStop Color="#FFBEAFAF" Offset="0.556"/>
</LinearGradientBrush>
</Path.Stroke>
</Path>
<Button Content="Button" HorizontalAlignment="Right" Margin="0,0,32,0" Style="{StaticResource ButtonStyle3}" Width="33"/>
</Grid>
</Grid>
</UserControl>
就这样一个简单的对话框按钮设计就基本完成了,blend很强大!我想只要自己有想法,仔细去剖析设计构思,我想程序员做美工的活儿也未尝不可!希望能够对你有所帮助!
源代码下载:XamlDemo1.zip