我有一个 Style 指定 Paragraph 作为我的一部分 FlowDocumentReader的资源部分:

<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 它有一些 Paragraphs被定义为:

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

我的问题是 Foreground 不适用于文本(它显示为黑色而不是LightSteelBlue)和 FontSizeMyFontSize 属性已修改。

我已经检查了后面的代码中的属性值,但它已设置,但不会导致UI的更改。

这似乎只是一个问题 FlowDocument 如果将其加载到 FlowDocumentReader 在运行时。如果XAML明确放置在 FlowDocumentReader 在.xAML文件中 Foreground 是正确的颜色, FontSize 基于属性设置的更改。

想法?


解决了:

正如我在下面的回答中所写的那样,通过移动 Style 阻止进入资源部分 FlowDocument 本身解决了问题。

有帮助吗?

解决方案 2

好吧,我通过将样式块从FlowdocumentReader资源中移出并进入FlowDocument本身的资源部分来解决此问题。最终的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>

其他提示

您是否尝试过直接为段落设置前景?它必须是管理目录前景的不同的prop/附加属性。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top