为什么以下简化代码未将TextBlock的字体大小设置为50?ControlTemplate中的ContentPresenter无法更改附加依赖项属性
<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只是将您提供给它的内容替换为自己。 – decyclone 2010-06-17 15:51:34