Silverlight:TargetType 的多个值?
我可以在 Silverlight 4 中定义如下样式:
<Style x:Name="Subtitle" TargetType="TextBlock">
<Setter Property="Foreground" Value="#787878" />
<Setter Property="FontWeight" Value="Light" />
</Style>
但是,我也想将这些属性应用到 Run
。我可以为 TargetType
设置多个值,或者以某种方式让这些样式沿着树传播吗?
I can define a style as follows in Silverlight 4:
<Style x:Name="Subtitle" TargetType="TextBlock">
<Setter Property="Foreground" Value="#787878" />
<Setter Property="FontWeight" Value="Light" />
</Style>
However, I want to apply these properties to a Run
as well. Can I have multiple values for the TargetType
, or somehow have these styles propagate down the tree?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,您可以创建一个针对公共基类的样式,然后创建从基样式派生的空样式以针对特定的类。但是,对于 TextBlock 和 Run,它们不共享公共基类,事实上,由于 Run 不是从 FrameworkElement 派生的,因此它甚至没有 Style 属性。
但是,如果您询问 Run 是否会继承其父 TextBlock 的前景/字体属性,那么是的。但是您将无法将此样式应用于独立于其包含的 TextBlock 的 Run。
另一种选择是为前景画笔和字体粗细创建静态资源,如下所示:
Normally you can create a style that targets a common base class and then create empty styles that derive from the base style to target the specific classes. However, in the case of TextBlock and Run, they do not share a common base class and in fact, since Run doesn't derive from FrameworkElement, it doesn't even have a Style property.
However, if you're asking whether a Run will inherit the foreground/font properties of its parent TextBlock, then yes it will. But you won't be able to apply this style to a Run independently of its containing TextBlock.
Another option is to create static resources for your foreground brush and font weight like so:
不..一种样式 - 一种目标类型...
Nope.. one Style - one TargetType...