目录
二、添加代码到App.xaml页面的Application.Resources里
三、在每个按钮的代码里,插入:Style="{StaticResource MyButton}"
一、最终实现的效果
如图所示,有四个按钮:板块、Word、Text、P-R。这四个按钮。这四个按钮之间无边界,并且当鼠标悬停到某一个按钮时,不会使得整个按钮带高亮效果,只会显示文字,并且高亮文字,这就特别符合简约风的风格,也是现在比较热门的按钮风格之一。
二、添加代码到App.xaml页面的Application.Resources里
<Style x:Key="MyButton" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border" BorderThickness="0" BorderBrush="Black" Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" Value="0.8" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
三、在每个按钮的代码里,插入:Style="{StaticResource MyButton}"