• 使用静态资源设置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="30"/>
            <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="ViewMainMainWindow.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="301" Width="509" Style="{StaticResource UserWindow }">
    看Style=这样设置

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

  • 相关阅读:
    SQL总结----存储过程
    SQL SERVER中的二种获得自增长ID的方法
    C#调用存储过程的ADO.Net
    扩展jQuery---选中指定索引的文本
    使用带参数的SQL语句向数据库中插入空值
    js中对小数取整
    Lr原理初识-慧测课堂笔记
    Https 安全传输的原理
    静态性能测试-慧测课堂笔记
    Docker常用命令
  • 原文地址:https://www.cnblogs.com/Ares-blog/p/4401040.html
Copyright © 2020-2023  润新知