style的继承
第一种方式:瞄准控件的基类
如下例所示,继承ContentControl的控件,都可以使用这个Style
<Window.Resources>
<Style x:Key="ContentControlStyle" TargetType="ContentControl">
<Setter Property="Background" Value="Pink"></Setter>
<Setter Property="FontSize" Value="12"></Setter>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Label Style="{StaticResource ContentControlStyle}" Content="按钮和文本框使用了基于ContentControl的Style"></Label>
<Button Style="{StaticResource ContentControlStyle}" Content="按钮" Grid.Row="1"></Button>
</Grid>
第二种方式:继承
<Window.Resources>
<Style x:Key="baseStyle" TargetType="Button">
<Setter Property="Background" Value="Pink"></Setter>
<Setter Property="FontSize" Value="12"></Setter>
</Style>
<Style x:Key="childStyle" TargetType="Button" BasedOn="{StaticResource baseStyle}">
<Setter Property="FontSize" Value="50"></Setter>
</Style>
</Window.Resources>
<Grid>
<Button Style="{StaticResource childStyle}" Content="按钮"></Button>
</Grid>
就近原则:父类子类同时设定属性,调用子类,以子类为准
示例代码
https://github.com/zLulus/NotePractice/tree/dev3/WPF/WpfDemo/Style 的StyleInheritDemo和StyleInheritDemo2
style的继承的更多相关文章
- wpf Style也继承(包含内部定义事件)
如何在既定皮肤下为某个style添加内容是我今天碰的问题,皮肤往往是对全局control进行设置的,当然这就无法满足某个个性十足的“另类”了,比如当使用DataGridCheckBoxColumn时, ...
- 安卓笔记--Style的继承
比如想要重写一个对话框的style <style name="Theme_dialog" parent="@android:style/Theme.Dialog&q ...
- Android style 继承
style作用在单个视图或控件上,抽取共有的属性,实现复用. style的继承有两种方式: 通过parent标识父style <style name="GreenText" ...
- Style在Android中的继承关系
Style在Android中的继承关系 Android的Styles(样式)和Themes(主题)非常类似Web开发里的CSS,方便开发者将页面内容和布局呈现分开.Style和Theme在Androi ...
- WPF整理-Style
"Consistency in a user interface is an important trait; there are many facets of consistency, ...
- WPF QuickStart系列之样式和模板(Style and Template)
在WPF桌面程序中,当我们想构建一个统一的UI表现时(在不同操作系统下,显示效果一致),此时我们就需要使用到WPF中的样式和模板技术.简单来说,如果我们需要简单的给一个Button设置宽,高,Marg ...
- Android的Style的使用
Style个人理解就是view的一些属性的集合,那么一系列view(例如TextVIew),只要是要该style那么就都有相同的内容,如 文字的大少,颜色等,方便修改 首先最基本的使用,多个textV ...
- Android中Style和Theme的使用
Style: Style是View中一些属性的集合,包括height,padding,font color,background等等,Style单独定义在xml文件中,类似与web页面中css的角色, ...
- Android中theme.xml与style.xml的区别
一.相同点 两者的定义相同.继承方式也相同 <?xml version="1.0" encoding="utf-8"?> <resources ...
随机推荐
- Apache+tomcat的整合 分类: C_OHTERS 2014-05-07 15:08 293人阅读 评论(0) 收藏
http://blog.csdn.net/stefyue/article/details/6918542 为什么要做这个整合呢?当然,首先想到是就是Apache和Tomcat的区别.正因为有区别,有各 ...
- js动态获取地址栏后的参数
原文链接:https://blog.csdn.net/qq_37936542/article/details/78866651 需求:js动态的获取地址栏后面的参数 js代码: alert(GetQu ...
- CoreData使用方法二:NSFetchedResultsController实例操作与解说
学习了NSFetchedResultsController.才深深的体会到coredata的牛逼之处.原来Apple公司弄个新技术.不是平白无故的去弄,会给代码执行到来非常大的优点.coredata不 ...
- Birt
http://www.eclipse.org/birt/ 咖啡图 http://www.kafeitu.me/activiti/2012/05/26/kft-activiti-demo.html
- android 连接USB按power键锁屏2声锁屏音
alps\frameworks\base\packages\Keyguard\src\com\android\keyguard\KeyguardViewMediator.java #1384 行左右: ...
- javaScript判断输入框是否为空
其中获得和失去焦点的时候都判断了一次 <script> function fun01(f,s){//有参函数 参数不需要参数类型!! try{ var v = document.getEl ...
- JSP的C标签遍历Map数据
JSP的C标签遍历Map数据 Map可以实现较为丰富的数据封装. 第一种: 控制器传递到页面的map格式如下: Map<String, User> dataMap = new HashMa ...
- shell脚本一键安装mysql5.7.x(免安装版)
使用脚本一键安装mysql5.7.x,初始化数据库,启动数据库---- mysql版本:源码mysql5.7.10 linux版本:centos6.5 x86_64 #!/bin/bash GROUP ...
- Android最新组件RecyclerView,替代ListView
转载请注明出处:http://blog.csdn.net/allen315410/article/details/40379159 万众瞩目的android最新5.0版本号不久前已经正式公布了,对于我 ...
- R 语言文件读写
1. working directory:工作目录 > getwd() > setwd("C:/data") # 设定当前工作目录 2. 读取格式化的 table &g ...