0

の Resources セクションの一部としてStyle指定された forがあります。ParagraphFlowDocumentReader

<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>

my を含む .xaml ファイルがあり、次のように定義されFlowDocumentている s がいくつかあります。Paragraph

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

私が抱えている問題はForeground、テキストに適用されず (LightSteelBlue ではなく Black として表示される) 、プロパティが変更されFontSizeても変更されないことです。MyFontSize

コード ビハインドでプロパティ値を確認しましたが、設定されていますが、UI に変更はありません。

これは、実行時FlowDocumentにロードされた場合にのみ問題になるようです。FlowDocumentReaderXAML がFlowDocumentReader.xaml ファイルの内に明示的に配置されている場合、Foregroundは正しい色でありFontSize、プロパティの設定に基づいて変更されます。

アイデア?


解決済み:

以下の回答で書いたように、Styleブロックをリソースセクションに移動FlowDocumentすると、問題が解決します。

4

2 に答える 2

0

さて、Style ブロックを FlowDocumentReader Resources から 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>
于 2011-01-26T18:49:25.000 に答える
0

段落の前景を直接設定しようとしましたか? コンテンツのフォアグラウンドを管理する別のプロパティ/添付プロパティである必要があります。

于 2011-01-26T15:57:49.760 に答える