【发布时间】:2011-06-15 22:39:23
【问题描述】:
我为Paragraph 指定了一个Style,作为我的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 不适用于文本(它显示为 Black 而不是 LightSteelBlue),并且 FontSize 在修改 MyFontSize 属性时不会改变。
我检查了后面代码中的属性值,它已设置,但不会导致 UI 发生变化。
这似乎只是FlowDocument 在运行时加载到FlowDocumentReader 时的问题。如果 XAML 明确放置在 .xaml 文件中的 FlowDocumentReader 内,则 Foreground 是正确的颜色,FontSize 会根据属性设置而变化。
想法?
已解决:
正如我在下面的回答中所写,通过将 Style 块移动到 FlowDocument 的资源部分本身可以解决问题。
【问题讨论】:
标签: wpf xaml binding styles dynamicresource