首页 > 其他分享 >全局样式和资源字典

全局样式和资源字典

时间:2023-11-22 11:13:07浏览次数:29  
标签:样式 引用 key 全局 资源 字典

全局样式和资源字典


  1. 在解决方案中添加资源字典buttonStytle,最好自定义个文件夹放里边。如图:
    img
  2. 资源字典中写样式,注意基样式可以有key可以无key。
    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    
        <!--基类样式无key-->
         <Style TargetType="Button">
            <Setter Property="Background" Value="Yellow"/>
        </Style>
        <!--注意BaseOn写法-->
        <Style TargetType="Button" x:Key="startButton" BasedOn="{StaticResource {x:Type Button}}">
            <Setter Property="Width" Value="200"/>
        </Style>
    
        <!--基类样式有key-->
        <Style TargetType="Button" x:Key="quitButtonBase">
            <Setter Property="Background" Value="Blue" />
        </Style>
        <!--注意BaseOn写法-->
        <Style TargetType="Button" x:Key="quitButton" BasedOn="{StaticResource quitButtonBase}">
            <Setter Property="Width" Value="200"/>
        </Style>
    
    </ResourceDictionary>
    
  3. App.xaml中引用资源字典, <ResourceDictionary Source="/WPFUI;component/资源字典路径" />
     <Application
     x:Class="WPFUI.App"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:local="clr-namespace:WPFUI"
     StartupUri="MainWindow.xaml">
    
     <Application.Resources>
         <ResourceDictionary>
             <ResourceDictionary.MergedDictionaries>
                 <ResourceDictionary Source="/WPFUI;component/style/buttonStyle.xaml" />
             </ResourceDictionary.MergedDictionaries>
         </ResourceDictionary>
    
     </Application.Resources>
     </Application>
    
  4. 控件引用样式
    <Window x:Class="WPFUI.MainWindow"
         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"
         xmlns:local="clr-namespace:WPFUI"
         mc:Ignorable="d"
         Title="MainWindow" Height="450" Width="800">
     <Grid>
         <StackPanel>
             <Button Content="开始" Style="{StaticResource startButton}"/>
             <Button Content="结束" Style="{StaticResource quitButton}"/>
         </StackPanel>
     </Grid>
     </Window>
    
  5. 结束。

标签:样式,引用,key,全局,资源,字典
From: https://www.cnblogs.com/zhanghanbao/p/17848512.html

相关文章

  • v-html 中的样式覆盖
    v-html里的内容样式如果直接在style里覆盖样式,不生效。需要样式穿透才行<template><divv-html="goodDetails.introduction"class="introduction"></template><stylelang="scss"scoped>.introduction/deep/img{ width:100%......
  • 字典中x in dict 和 x in dict.keys()速度不同,前者最快
    classSolution(object):deffindMaxLength(self,nums):""":typenums:List[int]:rtype:int"""#长度2-》1#长度3-》0#长度4-》2#长度5-》0#长度6-》3......
  • element-ui全局添加加载遮罩层
    创建loading.js文件import{Loading}from'element-ui';letloadingCount=0;letloading;conststartLoading=()=>{loading=Loading.service({lock:false,spinner:'el-icon-loading',background:'rgba(0,0,0,.5)......
  • crunch 生成字典
    生成4位验证码crunch44-d2%-t%%%%>crunch.out1、各种符号%代表数字@代表小写字母,代表大写字符^代表特殊符号2、选项-t指定输出格式 -t  %%%%  输出四位纯数字-d允许相同元素最多连续出现的次数-d  2% ......
  • jquery 检测div宽度变化_jquery判断浏览器宽度小于指定值改变div样式
    浏览器原本样式当浏览器宽度小于1200px时样式变为代码如下:方法一:直接修改该div样式添加w1200,会覆盖前一个样式$(function(){var_width=$(window).width();//获取浏览器宽度if(_width<1200){$(".chenbin_org").addClass("w1200");}});方法二:修改该div的class属性......
  • Vue动态改变css样式的3种方法
    在网页开发中,我们经常会遇到动态的改变某个元素样式的需求,在vue里如何实现呢?官网上其实写的很详细了,对象语法,数组语法等。我自己总结了在开发中,个人用的比较多的三种方式1.class,三元表达式:class="[occupation==='请选择'?'lh60':'lh61']"css.red{color:red;}.blue......
  • (uniapp)小程序实现自定义弹框,自定义样式showmodal
    在components里新建自定义弹框组件——modal.vue<template><!--自定义弹窗--><viewclass="_showModal"v-show="show"><viewclass="_shade"></view><viewclass="_modalBox">......
  • vue3 基础-Pinia 可能替代 Vuex 的全局数据状态管理
    Pinia初体验Pinia.js是由Vue.js团队核心成员开发的新一代状态管理器,使用CompositionApi进行重新设计的,也被视为下一代Vuex。Pinia是一个Vue的状态管理库,允许跨组件、跨页面进行全局共享状态,也由于其设计的简洁性、和对typescript的良好支持,取代Vuex指日可待。或许,你在想在vue......
  • 4、全局样式使用
    1、在assets文件下面创建css样式文件,如:assets/css/global.css 2、引用全局样式,在main.ts文件里面引用样式文件 3、页面效果如下  ......
  • 解决icloud邮箱ssl网络错误的一种,全局代理配置有问题
    SSL错误也可能是因为代理配置今天,折腾我的macbookpro2015,发现邮件功能不能使用。而且更新系统也不行,网络不畅。最后发现原因,平时我使用谷歌学术助手igg和谷歌浏览器,这掩盖了系统全局代理一直处于错误配置的状态。并且以前配置了全局代理。但是一年到期了,没有续费会员。导致我的mac......