一、简单实例。文件分布。
二、Style文件类型是这样的
三、WPF View页面(MainWindow.xaml)
需要写这代码;
<Window x:Class="WPFiveStar.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Style/Style.xaml"/> //红色字体是实现重点
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Button Content="Click me" x:Name="Button_key" Width="150" Height="50" Style="{StaticResource Button_key}"/>
</Grid>
</Window>
四、Style页面
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="Button_key" TargetType="Button">
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontSize" Value="14"/>
</Style>
</ResourceDictionary>
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="Button_key" TargetType="Button">
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontSize" Value="14"/>
</Style>
</ResourceDictionary>