zoukankan      html  css  js  c++  java
  • 使用静态资源设置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=这样设置

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

  • 相关阅读:
    2018年第九届蓝桥杯【C++省赛B组】第二题 明码
    2018年第九届蓝桥杯【C++省赛B组】第三题 乘积尾零
    2018年第九届蓝桥杯【C++省赛B组】第四题 测试次数
    L2-023 图着色问题
    L2-011 玩转二叉树
    获取当前的时间,转化为char[]格式unix时间戳
    创建子进程
    strerror
    gdb
    gcc
  • 原文地址:https://www.cnblogs.com/Ares-blog/p/4401040.html
Copyright © 2011-2022 走看看