c# – WPF:如何在css中类似一个类?

栏目: C# · 发布时间: 7年前

内容简介:代码日志版权声明:翻译自:http://stackoverflow.com/questions/5186773/wpf-how-to-style-a-class-like-in-css

假设我有一个UserControl与4边界:

<Border />
<Border />
<Border />
<Border />

现在在我的资源我可以去:

<Style TargetType="{x:Type Border}">
  ... change some properties here
</Style>

现在这一切都很好,但它将针对我的UserControl中的所有边框.

但是,如果我只想瞄准一个子集呢?

我想去:

<Border Class="Type1" />
<Border Class="Type1" />
<Border />
<Border />

然后去:

<Style TargetType="{x:Type Border}" TargetClass="Type1">
  ... change some properties here
</Style>

但这显然不存在,还有其他一些方法可以实现我以后吗?

谢谢

虽然语法不如CSS那么干净,但它更具体.

要建立在你的例子上,你要找的是:

<Border Style="{StaticResource Type1}" />
<Border Style="{StaticResource Type1}" />
<Border />
<Border />

然后去:

<Style TargetType="{x:Type Border}" x:Key="Type1">
  ... change some properties here
</Style>

记住,WPF样式并不像CSS那样实际上级联.

代码日志版权声明:

翻译自:http://stackoverflow.com/questions/5186773/wpf-how-to-style-a-class-like-in-css


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

C++ How to Program (5th Edition) (How to Program)

C++ How to Program (5th Edition) (How to Program)

Harvey & Paul) Deitel & Associates / Prentice Hall / 2005-01-05 / USD 98.00

With over 250,000 sold, Harvey and Paul Deitel's C++ How to Program is the world's best-selling introduction to C++ programming. Now, this classic has been thoroughly updated! The Deitels' groundbreak......一起来看看 《C++ How to Program (5th Edition) (How to Program)》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具