使用静态资源设置UI信息

首先建立一个文件存放样式设置(资源字典),所有风格设置都可以这里进行

加入以下代码:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <!--窗体风格设置-->
<Style x:Key="UserWindow" TargetType="{x:Type Window}">
<Setter Property="FontFamily" Value="微软雅黑"/>
<Setter Property="FontSize" Value=""/>
<Setter Property="BorderBrush" Value="Blue"/>
<Setter Property="FontWeight" Value="Black"/>
</Style>
</ResourceDictionary>

资源字典代码

在APP.xaml中进行以下设置

<Application x:Class="OilSystem.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
StartupUri="View\Main\MainWindow.xaml"
mc:Ignorable="d"> <Application.Resources>
<!--Global View Model Locator-->
<!--<vm:ViewModelLocator x:Key="Locator"
d:IsDataSource="True" />-->
<!--下面这行代码就是需要用到的资源字典-->
<ResourceDictionary Source="Skins/WindowExpanderStyle.xaml"/>
</Application.Resources> </Application>

APP.xaml文件设置

调用时按以下方法

<Window x:Class="OilSystem.View.Main.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="" Width="" Style="{StaticResource UserWindow }">

看Style=这样设置

运行下看看效果吧,皮肤设置就是这样做的,更改资源字典的内容就可以直接更换风格

上一篇:(多对象)Json转换成List


下一篇:用RecyclerView做一个小清新的Gallery效果 - Ryan Lee的博客