2011-01-26 44 views
0

我有一個指定ParagraphStyle爲我FlowDocumentReader的資源部分的一部分:WPF樣式並不影響某些屬性

<FlowDocumentReader> 
    <FlowDocumentReader.Resources> 
     <Style x:Key="myStyle" TargetType="{x:Type Paragraph}"> 
     <Setter Property="Foreground" Value="LightSteelBlue" /> 
     <Setter Property="BorderBrush" Value="LightSteelBlue" /> 
     <Setter Property="BorderThickness" Value="1.0" /> 
     <Setter Property="FontStyle" Value="Italic" /> 
     <Setter Property="FontSize" Value="{Binding Path=MyFontSize}" /> 
     </Style> 
    </FlowDocumentReader.Resources> 
</FlowDocumentReader> 

我有一個的.xaml文件,其中包含我的FlowDocument它有一些Paragraph S的被定義爲這樣:

<Paragraph Style='{DynamicResource myStyle}"> 
    Stuff here 
</Paragraph> 

,我有是Foreground並不適用於文本的問題(它顯示爲黑色,而不是淺鋼)和當修改MyFontSize屬性時,不會更改。

我已檢查後面的代碼中的屬性值,它已設置,但它不會導致UI中的更改。

如果在運行時將其加載到FlowDocumentReader,這似乎只是FlowDocument的一個問題。如果XAML明確放在FlowDocumentReader內的文件名爲.xaml的Foreground是正確的顏色,並基於該屬性設置FontSize變化。

想法?


解決:

正如我在我的回答如下寫道,由Style塊移動到FlowDocument自身解決問題的資源部分。

回答

0

好吧,我通過將Style塊移出FlowDocumentReader資源並將其移入FlowDocument本身的Resources部分來解決此問題。由此產生的FlowDocument看起來像這樣:

<FlowDocument> 
    <FlowDocument.Resources> 
     <Style x:Key="myStyle" TargetType="{x:Type Paragraph}"> 
     <Setter Property="Foreground" Value="LightSteelBlue" /> 
     <Setter Property="BorderBrush" Value="LightSteelBlue" /> 
     <Setter Property="BorderThickness" Value="1.0" /> 
     <Setter Property="FontStyle" Value="Italic" /> 
     <Setter Property="FontSize" Value="{Binding Path=MyFontSize}" /> 
     </Style> 
    </FlowDocument.Resources> 
    <Paragraph Style="{DynamicResource myStyle}"> 
     Stuff here 
    </Paragraph> 
</FlowDocument> 
0

您是否嘗試過直接爲您的段設置前景?它必須是一個不同的管理內容前景的主要/附屬屬性。

+0

是的,如果我設置paragraph.Foreground =新的SolidColorBrush(Colors.Red),它會改變顏色。 – itsmatt