块/内联上的样式属性 - 有没有办法得到这个?
我正在 SL4Beta 中使用新的 RichTextBox 控件,并且想要为段落和行(块和内联)创建样式。我注意到我可以为
创建样式,如下所示:
<Style x:Key="lvl2Paragraph" TargetType="Block">
<Setter Property="FontFamily" Value="Times New Roman"/>
<Setter Property="FontStyle" Value="Italic"/>
<Setter Property="FontSize" Value="22"/>
</Style>
但我不能将其设置为
as 成员“Style”成员无法识别或不可访问。像这样:
<RichTextBox TextWrapping="Wrap">
<Paragraph Style="{StaticResource lvl2Paragraph}">
Can't set a style for a paragraph.
</Paragraph>
</RichTextBox>
有没有办法让“Style”暴露给RichTextBox?我对所有想法持开放态度。
I'm using the new RichTextBox control in SL4Beta and want to create styles for paragraphs and runs (blocks and inlines). I noticed that I can create a style for a <Block/>
, like so:
<Style x:Key="lvl2Paragraph" TargetType="Block">
<Setter Property="FontFamily" Value="Times New Roman"/>
<Setter Property="FontStyle" Value="Italic"/>
<Setter Property="FontSize" Value="22"/>
</Style>
But I can't set that to a <Paragraph/>
as The member "Style" member is not recognized or not accessible. Like this:
<RichTextBox TextWrapping="Wrap">
<Paragraph Style="{StaticResource lvl2Paragraph}">
Can't set a style for a paragraph.
</Paragraph>
</RichTextBox>
Is there anyway to make "Style" exposed for the RichTextBox? I'm open to all ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Style
是继承自FrameworkElement
的元素支持的属性和机制。然而,RichTextBox
的内容是轻量级的,它们在其类祖先中没有FrameworkElement
甚至UIElement
。我能想到的缓解这种情况的唯一方法是创建一个附加属性来代替缺少的
Style
属性。但是,您可以在该附加属性中实现其他属性的所有设置。如果内联 Xaml 也设置相同的属性,则会对文档顺序敏感。Style
is a property and mechanism supported by elements that inherit fromFrameworkElement
. However the contents ofRichTextBox
are lightweight, they do not haveFrameworkElement
or evenUIElement
in their class ancestory.The only way I can think of to mitigate this is to create an Attached property to take the place of the missing
Style
property. However you would have implement in that attached property all the setting of the other properties. It would sensitive to document order if inline Xaml also sets the same properties.