WPF Button Color Style

直接上效果图


<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 &#xd;&#xa;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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值