是否可以在 Silverlight ContentPresenter 中嵌入文本格式?
我刚刚开始使用样式和控件模板,并创建了以下样式以将按钮显示为网格中的文本。我想将字体样式嵌入到下划线样式中,但还没有弄清楚。
<Style x:Key="TextButtonStyle" TargetType="Button">
<Setter Property="Background" Value="LightGray" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<ContentPresenter Content="{TemplateBinding Content}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="TextButtonInGridStyle" TargetType="Button" BasedOn="{StaticResource TextButtonStyle}">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="4,4,4,4" />
</Style>
我想将字体样式嵌入到下划线样式中,但还没有弄清楚。有没有办法在不将 TextBlock 嵌入 ControlTemplate 或在 Button 元素声明中嵌套 TextBlock 的情况下执行此操作?
谢谢
I have just started working with with Styles and Control Templates and have created the following styles to display a button as text in a grid. I would like to embed Font Styling into the styles for underlining but have not figured it out.
<Style x:Key="TextButtonStyle" TargetType="Button">
<Setter Property="Background" Value="LightGray" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<ContentPresenter Content="{TemplateBinding Content}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="TextButtonInGridStyle" TargetType="Button" BasedOn="{StaticResource TextButtonStyle}">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="4,4,4,4" />
</Style>
I would like to embed Font Styling into the styles for underlining but have not figured it out. Is there any way to do this without embedding a TextBlock into the ControlTemplate or nesting a TextBlock in the Button element declaration?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你绝对可以,或者也许我不明白这个问题,但看看这个例子是否是你想要的:
您可以看到按钮中没有 TextBlock,如果内容是矩形,它将很好地显示而不是文本。
You definitely can, or maybe I don't understand the problem, but see if this example is what you're after:
You can see that there's no TextBlock in the Button, and if the content is a rectangle it'll be shown instead of the text nicely.