App.xaml、App.xaml.cs、MainWindow.xaml、MainWindow.xaml.cs
App.xaml是负责应用内部的资源管理,
App.xaml.cs是负责App.xaml的交互逻辑,
MainWindow.xaml是负责页面布局脚本,
MainWindow.xaml.cs是负责页面控件交互逻辑的管理。
写App.xaml设计一下按钮的形式风格
Application.Resources里添加如下代码
<!--点击按钮背景顔色-->
<LinearGradientBrush x:Key="LinearGradientBlueBackground" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF2F70BD" Offset="0" />
<GradientStop Color="#FF5278B8" Offset="1" />
</LinearGradientBrush>
<!--按钮外边框顔色-->
<SolidColorBrush x:Key="MyBtnBorderColor" Color="#FF2D78F4"></SolidColorBrush>
<SolidColorBrush x:Key="MyBtnHoverBackgroundColor" Color="#FF317EF3"></SolidColorBrush>
<!--END-->
<Style x:Key="MyWpfButton" TargetType="{x:Type Button}" >
<!--设置按钮颜色-->
<Setter Property="Background" Value="{StaticResource LinearGradientBlueBackground}"></Setter>
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="BorderBrush" Value="{StaticResource MyBtnBorderColor}"></Setter>
<!--设置按钮圆角-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="true" CornerRadius="5,5,5,5">
<!--设置圆角尺寸-->
<ContentPresenter x:Name="contentPresenter"
Focusable="False"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<!--设置触发事件,鼠标悬在按钮上方时按钮变成淡蓝色-->
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="border" Value="{StaticResource MyBtnHoverBackgroundColor}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>