【发布时间】:2010-06-17 15:44:03
【问题描述】:
为什么下面的简化代码没有将 TextBlock 的 font-size 设置为 50?
<Window.Resources>
<ControlTemplate TargetType="ContentControl" x:Key="Test">
<ContentPresenter TextBlock.FontSize="50" />
</ControlTemplate>
</Window.Resources>
<Grid>
<ContentControl Template="{StaticResource Test}">
<TextBlock>Test should be rendered big</TextBlock>
</ContentControl>
</Grid>
如果我更改 FontSize 属性的值,Visual Studio 会以我想要的大小显示文本。编译或执行应用程序后,文本块的大小始终重置为其默认大小。
我还测试了带有样式和嵌入式资源的各种版本,但我总是在无法设置从包含 ContentPresenter 的 ControlTemplate 中继承附加的 dp 的情况下结束。这是设计的吗?
【问题讨论】:
-
以前从未遇到过这样的情况,但可能是设计使然。我认为 ContentPresenter 只是将自己替换为您提供给它的内容。
标签: wpf controltemplate contentpresenter