第一种方式:瞄准控件的基类

如下例所示,继承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的继承的更多相关文章

  1. wpf Style也继承(包含内部定义事件)

    如何在既定皮肤下为某个style添加内容是我今天碰的问题,皮肤往往是对全局control进行设置的,当然这就无法满足某个个性十足的“另类”了,比如当使用DataGridCheckBoxColumn时, ...

  2. 安卓笔记--Style的继承

    比如想要重写一个对话框的style <style name="Theme_dialog" parent="@android:style/Theme.Dialog&q ...

  3. Android style 继承

    style作用在单个视图或控件上,抽取共有的属性,实现复用. style的继承有两种方式: 通过parent标识父style <style name="GreenText" ...

  4. Style在Android中的继承关系

    Style在Android中的继承关系 Android的Styles(样式)和Themes(主题)非常类似Web开发里的CSS,方便开发者将页面内容和布局呈现分开.Style和Theme在Androi ...

  5. WPF整理-Style

    "Consistency in a user interface is an important trait; there are many facets of consistency,   ...

  6. WPF QuickStart系列之样式和模板(Style and Template)

    在WPF桌面程序中,当我们想构建一个统一的UI表现时(在不同操作系统下,显示效果一致),此时我们就需要使用到WPF中的样式和模板技术.简单来说,如果我们需要简单的给一个Button设置宽,高,Marg ...

  7. Android的Style的使用

    Style个人理解就是view的一些属性的集合,那么一系列view(例如TextVIew),只要是要该style那么就都有相同的内容,如 文字的大少,颜色等,方便修改 首先最基本的使用,多个textV ...

  8. Android中Style和Theme的使用

    Style: Style是View中一些属性的集合,包括height,padding,font color,background等等,Style单独定义在xml文件中,类似与web页面中css的角色, ...

  9. Android中theme.xml与style.xml的区别

    一.相同点 两者的定义相同.继承方式也相同 <?xml version="1.0" encoding="utf-8"?> <resources ...

随机推荐

  1. Opencv在视频中静态、动态方式绘制矩形框ROI

    Opencv视频处理中的目标跟踪经常用到要在视频上画一个矩形框ROI,标注出要跟踪的物体,这里介绍两种在视频中绘制矩形框的方法,一种是"静态的",一种是"动态的" ...

  2. Android自己定义控件2-简单的写字板控件

    概述 上一篇文章我们对自己定义控件进行了一个大体的知识介绍. 今天就来学习自己定义一个简单的写字板控件. 先来看看效果图 就是简单的依据手指写下的轨迹去画出内容 实现 在上一篇文章里提到了androi ...

  3. 小强的HTML5移动开发之路(43)——JqueryMobile页眉、工具栏和标签栏导航

    一.页眉 1.添加页眉和页脚 <div data-role="header"> <h1>第 1 页</h1> </div> < ...

  4. [React] Pass Data To Event Handlers with Partial Function Application

    In this lesson we’ll see how to pass an item’s id value in an event handler and get the state to ref ...

  5. java完美equals方法代码段

    public boolean equals(Object otherObject) { if(this == otherObject) { // 检測this与otherObject是否引用同一个对象 ...

  6. java线程池框架源代码分析

    相关类Executor,Executors.AbstractExecutorService.ExecutorService Executor:整个线程池运行者框架的顶层接口. 定义了一个execute ...

  7. MapKit

    MapKit MapKit框架的使用 nMapKit框架使用前提 p导入框架 p p导入主头文件 #import <MapKit/MapKit.h> MapKit框架使用须知 pMapKi ...

  8. virtualenv对python

    使用virtualenv对python进行多版本隔离 最近在用python做一个文本的情感分析的项目,用到tensorflow,需要用python3的版本,之前因为<机器学习实战>那本书的 ...

  9. 【codeforces 534C】Polycarpus' Dice

    [题目链接]:http://codeforces.com/contest/534/problem/C [题意] 给你n个奇怪的骰子,第i个骰子有di个面; 然后给你n个骰子的点数之和; 问你每一个骰子 ...

  10. 用决策树模型求解回归问题(regression tree)

    How do decision trees for regression work? 决策树模型既可以求解分类问题(对应的就是 classification tree),也即对应的目标值是类别型数据, ...