VS工程添加资源文件

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>

 

posted @ 2016-12-13 16:06  pkyou  阅读(11319)  评论(1编辑  收藏  举报