作为我的资源部分的一部分,我有一个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>
我有一个 .xaml 文件,其中包含 myFlowDocument并且它有一些Paragraph定义如下:
<Paragraph Style='{DynamicResource myStyle}">
Stuff here
</Paragraph>
我遇到的问题是Foreground不适用于文本(它显示为黑色而不是 LightSteelBlue),并且在修改属性FontSize时不会改变。MyFontSize
我检查了后面代码中的属性值并设置了它,但它不会导致 UI 发生变化。
FlowDocument如果它FlowDocumentReader在运行时加载到,这似乎只是一个问题。如果 XAML 显式放置在FlowDocumentReader.xaml 文件中,则Foreground它是正确的颜色,并且FontSize基于属性设置的更改。
想法?
解决了:
正如我在下面的回答中所写,通过将Style块移动到其本身的资源部分FlowDocument可以解决问题。