style的继承
2024-09-01 00:30:52
第一种方式:瞄准控件的基类
如下例所示,继承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
最新文章
- 纯CSS3实现多层云彩变换飞行动画
- 跳转页面,传递参数——android
- BZOJ2981 : [Poi2002]括号
- C# gridControl 部分设置
- U盘格式化后的恢复
- 转: SQL Server索引的维护 - 索引碎片、填充因子
- java jdbc----mysql的select、insert、update、delete
- 逻辑网络(Logical Network)
- android studio常用快捷键(不断补充)
- TreeView控件例子
- css Tab选项卡1
- 【转】flash air中读取本地文件的三种方法
- 从编译器角度理解C++中的引用和指针
- javascript templating
- POJ 2411 Mondriaan&#39;s Dream -- 状压DP
- [物理学与PDEs]第1章习题11 各向同性导体中电荷分布的指数衰减
- [CodeForce 450A] Jzzhu and Children
- AI Haar特征
- mysql学习笔记--数据库操作
- 通过sql语句修改表的结构
热门文章
- 解决Eclipse中文乱码 分类: B1_JAVA 2014-06-25 11:23 336人阅读 评论(0) 收藏
- 【C#】万事开头难(二)&;lt;机房重构&;gt;
- Android Error:(1,N1) 错误: 需要class, interface或enum
- php实现 提取不重复的整数(编程题目能够最快的熟悉函数)
- js进阶 11-7 jquery如何获取和改变元素的位置
- 数据库使用char要留心
- 学习游戏服务器开发必看,C++游戏服务器开发常用工具介绍
- Wpf的布局舍入属性(可以解决软件字体模糊的问题)
- 探险 - 树型dp(背包)/多叉树转二叉树
- Cocos2d-x 3.1.1 Lua演示样例 ActionManagerTest(动作管理)