1. 添加资源文件:
2. 资源文件内写相应代码:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MultiSerialPort.Resources"> <Style TargetType="Label"> <Setter Property="Foreground" Value="White"></Setter> </Style> <Style TargetType="Window"> <Setter Property="Background" Value="LightGray"></Setter> </Style> </ResourceDictionary>
3. App.xaml文件添加资源:
<Application x:Class="MultiSerialPort.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MultiSerialPort" StartupUri="MainWindow.xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Resources/Style.xaml"></ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>