原文:WPF 精修篇 样式继承

这个 是新知识 样式可以继承


  1. <Style x:Key="TextBlockStyleBase" TargetType="{x:Type TextBlock}">
  2. <Setter Property="TextWrapping" Value="NoWrap"/>
  3. <Setter Property="TextTrimming" Value="None"/>
  4. <Setter Property="Background" Value="#FF666666"/>
  5. <Setter Property="Foreground" Value="White"/>
  6. </Style>
  7. <Style x:Key="TextBlockStyle1" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource TextBlockStyleBase}">
  8. <Setter Property="Foreground" Value="Red"/>
  9. </Style>
  10. <Style x:Key="TextBlockStyle2" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource TextBlockStyleBase}">
  11. <Setter Property="Background" Value="Brown"/>
  12. <Setter Property="Foreground" Value="Beige"/>
  13. </Style>
  14. </Window.Resources>
  15. <Grid>
  16. <TextBlock HorizontalAlignment="Left" Height="42" Margin="60.5,43,0,0" TextWrapping="Wrap" Text="TextBlockBase" VerticalAlignment="Top" Width="228" Style="{DynamicResource TextBlockStyleBase}"/>
  17. <TextBlock HorizontalAlignment="Left" Height="42" Margin="60,112,0,0" TextWrapping="Wrap" Text="TextBlock1" VerticalAlignment="Top" Width="228" Style="{DynamicResource TextBlockStyle1}"/>
  18. <TextBlock HorizontalAlignment="Left" Height="42" Margin="60,179,0,0" TextWrapping="Wrap" Text="TextBlock2" VerticalAlignment="Top" Width="228" Style="{DynamicResource TextBlockStyle2}"/>
  19. </Grid>

定义了一个主样式 俩个样 用 BasedOn 来继承 修改 或增加 显示不同的效果

WPF 精修篇 样式继承的更多相关文章

  1. WPF 精修篇 获取系统颜色和字体样式

    原文:WPF 精修篇 获取系统颜色和字体样式 看效果 <Grid> <Rectangle Fill="{DynamicResource {x:Static SystemCo ...

  2. WPF 精修篇 依赖属性

    原文:WPF 精修篇 依赖属性 依赖属性使用场景 1. 希望可在样式中设置属性. 2. 希望属性支持数据绑定. 3. 希望可使用动态资源引用设置属性. 4. 希望从元素树中的父元素自动继承属性值. 5 ...

  3. WPF 精修篇 属性触发器

    原文:WPF 精修篇 属性触发器 属性触发器是通过  某个条件触发改变属性 通过无代码实现功能 <Style TargetType="{x:Type Label}"> ...

  4. WPF 精修篇 数据绑定 更新通知

    原文:WPF 精修篇 数据绑定 更新通知 开始更新一点有意思的了 首先 数据绑定  其中之一 Element 绑定 看例子 <Window x:Class="WpfApplicatio ...

  5. WPF 精修篇 管理资源字典

    原文:WPF 精修篇 管理资源字典 样式太多  每个界面可能需要全局的样式 有没有肯能 WPF 中的样式 像Asp.net中 的CSS一样管理那 有的 有资源字典 BurshDictionary &l ...

  6. WPF 精修篇 动态资源

    原文:WPF 精修篇 动态资源 动态资源 使用 DynamicResource 关键字 静态 就是 StaticResource 原则上是 能用静态就用静态 动态会让前台界面压力很大~ 动态资源引用 ...

  7. WPF 精修篇 静态资源

    原文:WPF 精修篇 静态资源 在WPF中 如果设置好了一个控件样式或者矩形样式 如果Copy出一个新的 那么样式也会双份 比如 下面的矩形 我定义好了一个 Copy 以后 就出现一个新的 但是改变样 ...

  8. WPF 精修篇 数据触发器

    原文:WPF 精修篇 数据触发器 数据触发器 可以使用Binding 来绑定控件 或者数据源 来触发相关动作 举栗子 <Window.Resources> <Style Target ...

  9. WPF 精修篇 自定义控件

    原文:WPF 精修篇 自定义控件 自定义控件 因为没有办法对界面可视化编辑 所以用来很少 现在实现的是 自定义控件的 自定义属性 和自定义方法 用VS 创建自定义控件后 会自动创建 Themes 文件 ...

随机推荐

  1. 为什么学习Python?

    互联网高速发展的今天,很荣幸能够接触计算机这个专业,成为一名程序猿小白,本科期间学习了C.C++.Java.Pthon.C#,每门语言都了解那么一点,学的很杂,刚好遇到大学毕业的这个暑期,在继续读研之 ...

  2. EF实体类指定部分属性不映射成数据库字段特性

    添加NotMapped 特性 /// <summary> /// 用户名 /// </summary> [NotMapped] public string user_name ...

  3. 图片切换器(ImageSwitcher)的功能与用法

    ImageSwitcher继承了ViewSwitcher,因此它具有与ViewSwitcher相同的特征:可以在切换View组件时使用动画效果.ImageSwitcher继承了ViewSwitcher ...

  4. [ERR] Node 172.16.6.154:7002 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.

    关于启动redis集群时: [ERR] Node 172.168.63.202:7001 is not empty. Either the nodealready knows other nodes ...

  5. Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt

    最近安装python,已经安装好,cmd终端中输入python.pip等命令都有用 然而在配置requirements.txt文件过程中,执行语句 “pip install -r requiremen ...

  6. java 主动信任证书

    java 主动信任证书 SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, mid.toCharArray() ...

  7. 剑指Offer-37.二叉树的深度(C++/Java)

    题目: 输入一棵二叉树,求该树的深度.从根结点到叶结点依次经过的结点(含根.叶结点)形成树的一条路径,最长路径的长度为树的深度. 分析: 递归求解左右子树的最大值即可,每遍历到一个结点,深度加1,最后 ...

  8. [译]Vulkan教程(11)Image Views

    Image views To use any VkImage, including those in the swap chain, in the render pipeline we have to ...

  9. SqlException:ConnectionTimeout Expired. The timeout period elapsed during the post-login phase

    linux系统部署.netcore程序后,访问某台sqlserver 2008 R2数据库 Connection Timeout Expired. The timeout period elapsed ...

  10. 21-django-pure-pagination分页

    一.django-pure-pagination分页 github上的描述(django-pure-pagination provides advanced pagination features a ...