爲什麼以下簡化代碼未將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