直接上效果图
<Window
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:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Luna" mc:Ignorable="d"
x:Class="WpfAppButton.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="376.5" Height="274" Background="#FFA1B4B6">
<Window.Resources>
<Style x:Key="ButtonFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="3" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<LinearGradientBrush x:Key="ButtonNormalBackgroundFill" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFFFFFF" Offset="0"/>
<GradientStop Color="#FFF0F0EA" Offset="0.9"/>
</LinearGradientBrush>
<Style x:Key="myExpandButtonStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
<Setter Property="Background" Value="{StaticResource ButtonNormalBackgroundFill}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Grid x:Name="grid" RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Grid.RenderTransform>
<Rectangle Fill="#FF40BE48" Stroke="{x:Null}" StrokeThickness="0" Opacity="0" Margin="4.684,3.979,6.378,5.834" RadiusY="0" Height="Auto" VerticalAlignment="Stretch"/>
<Path x:Name="path" Data="M5.8980706,13.542352 L15.316946,5.1993148 24.897892,13.618299 20.877304,13.646207 15.248735,8.7229148 9.5104679,13.611588 z" Height="11.438" Margin="4.672,3.979,6.39,0" Stretch="Fill" VerticalAlignment="Top" StrokeThickness="0" Opacity="0.995" Stroke="#FF18ED7D" Fill="#FF0FA33A" HorizontalAlignment="Center" Width="23.212"/>
<Path x:Name="path2" Data="M5.8980706,13.542352 L15.316946,5.1993148 24.897892,13.618299 20.877304,13.646207 15.248735,8.7229148 9.5104679,13.611588 z" Height="Auto" Margin="4.684,14.083,6.354,6.98" Stretch="Fill" VerticalAlignment="Stretch" StrokeThickness="0" Opacity="0.995" Stroke="#FF18ED7D" Fill="#FF0FA33A" HorizontalAlignment="Stretch" Width="Auto"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Fill" TargetName="path" Value="#FF0FDA25"/>
<Setter Property="Fill" TargetName="path2" Value="#FF0FDA25"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true"/>
<Trigger Property="ToggleButton.IsChecked" Value="true">
<Setter Property="RenderTransform" TargetName="grid">
<Setter.Value>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="180"/>
<TranslateTransform/>
</TransformGroup>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<SolidColorBrush x:Key="ButtonBorder" Color="#FF003C74"/>
<Style x:Key="colorButtonStyle" TargetType="{x:Type Button}">
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
<Setter Property="Background" Value="{StaticResource ButtonNormalBackgroundFill}"/>
<Setter Property="BorderBrush" Value="{StaticResource ButtonBorder}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid Height="Auto" Margin="0,0,3.5,0">
<Rectangle x:Name="rectangle" Fill="#FF0F0F7C" Stroke="{x:Null}" Opacity="1" RadiusX="5" RadiusY="5" StrokeThickness="0">
<Rectangle.Effect>
<DropShadowEffect ShadowDepth="1" BlurRadius="8"/>
</Rectangle.Effect>
</Rectangle>
<TextBlock Margin="5,3" TextWrapping="Wrap" Text="{TemplateBinding Content}" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="13.333" Height="Auto"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Stroke" TargetName="rectangle" Value="{x:Null}"/>
<Setter Property="StrokeThickness" TargetName="rectangle" Value="0"/>
<Setter Property="Fill" TargetName="rectangle" Value="#FF0F0FED"/>
<Setter Property="Opacity" TargetName="rectangle" Value="1"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Stroke" TargetName="rectangle" Value="#FF0A6E07"/>
<Setter Property="Opacity" TargetName="rectangle" Value="1"/>
<Setter Property="Effect" TargetName="rectangle">
<Setter.Value>
<DropShadowEffect BlurRadius="8" ShadowDepth="3"/>
</Setter.Value>
</Setter>
<Setter Property="StrokeThickness" TargetName="rectangle" Value="2"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true"/>
<Trigger Property="ToggleButton.IsChecked" Value="true"/>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<ToggleButton Name="toggle" Focusable="False" Content="expand" HorizontalAlignment="Right" Height="32.501" Margin="0,31.333,22.917,0" VerticalAlignment="Top" Width="34.25" Style="{DynamicResource myExpandButtonStyle}" BorderBrush="{x:Null}" RenderTransformOrigin="6.56,-5.735" d:LayoutOverrides="VerticalAlignment">
<ToggleButton.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="0.6" ScaleY="0.6"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform X="-83.021" Y="81.055"/>
</TransformGroup>
</ToggleButton.RenderTransform>
</ToggleButton>
<Button Content="Start 
2015.01.03" Focusable="False" HorizontalAlignment="Left" Margin="54,8,0,0" VerticalAlignment="Top" Style="{DynamicResource colorButtonStyle}"/>
<Button Content="Quantity Info" Focusable="False" HorizontalAlignment="Left" Margin="54,79,0,0" VerticalAlignment="Top" Style="{DynamicResource colorButtonStyle}"/>
<Button Content="Filter" Focusable="False" HorizontalAlignment="Left" Margin="54,0,0,96.27" VerticalAlignment="Bottom" Style="{DynamicResource colorButtonStyle}"/>
<Button Content="Button\niiii" HorizontalAlignment="Left" Height="26" Margin="54,0,0,28.667" VerticalAlignment="Bottom" Width="80.667"/>
</Grid>
</Window>
本文介绍了一种使用WPF进行按钮样式定制的方法,通过自定义样式实现独特的视觉效果。包括了扩展按钮、颜色按钮等样式的详细配置,适用于UI设计师和WPF开发者。
2171

被折叠的 条评论
为什么被折叠?



