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

如下例所示,继承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. [NativeScript] Create new application and run emulator

    Install: npm i -g nativescript Create: tns create <app_name> --ng Run: tns emulate ios List al ...

  2. js进阶 10-9 -of-type型子元素伪类选择器

    js进阶 10-9 -of-type型子元素伪类选择器 一.总结 一句话总结:三种和first.last等有关的选择器. 1.:first和:first-child和:first-of-type的区别 ...

  3. [SVG] Add an SVG as an Embedded Background Image

    Learn how to set an elements background image to embedded SVG. This method has an added benefit of n ...

  4. php课程 6-20 字符串基础和去除空格和字符串填补函数

    php课程 6-20  字符串基础和去除空格和字符串填补函数 一.总结 一句话总结: 二.字符串 字符串定义:$str='hello world!'; 输出字符串:echo $str;print $s ...

  5. 【27.40%】【codeforces 599D】Spongebob and Squares

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. error: openssl/md5.h: No such file or directory

    出现:error: openssl/md5.h: No such file or directory 原因是openssl-devel没有安装,运行: yum install libssl-dev 就 ...

  7. matlab 编程的细节问题

    1. reshape 对元素的操作 使用单一维度对矩阵进行操作时,矩阵是逐列地进行编号的(如下矩阵中的 4, 5, 6,分别在矩阵 A 的第 4, 5, 6 索引处,而不是以行进行排序的 2,5,8 ...

  8. 编译freetype 的dll

    因需要给python使用freetype库,so需要一个freetype的dll 2 steps 1. 在VC中设置输出为动态链接库 2. 修改ftoption.h 在284行增加2行代码即可 /** ...

  9. Android 开发新方向 Android Wear ——概述

    2014 谷歌 I/O大会正式公布的Android Wear 开发理念,从而能够更系统的提供开发人员使用Android接口开发便携式可穿戴设备,以智能手表为例,通过Android提供的接口,能够方便的 ...

  10. poi读取xlsx

    知道 大家都知道用poi读取xls  当时有时候 必需要读取xlsx  如今我把我做測试的demo分享给大家 package com.lt.main; import java.io.File; imp ...