如何将运行的背景画笔动态绑定到资源?
|
在我的app.xaml中:
<Application.Resources>
<SolidColorBrush x:Key=\"colorBrush1\" Color=\"Orange\" Opacity=\"1\"/>
<SolidColorBrush x:Key=\"colorBrush2\" Color=\"Green\" Opacity=\"1\"/>
</Application.Resources>
在我的代码背后:
Run run = new Run(\"My name is Bob!\");
run.SetResourceReference(ForegroundProperty, \"colorBrush1\");
run.SetResourceReference(BackgroundProperty, \"colorBrush2\");
Paragraph paragraph = new Paragraph(run);
this.flowDocument.Blocks.Add(paragraph);
预期结果:运行显示为具有上面app.xaml中定义的前景色和背景色。
实际结果:前景色起作用(显示为橙色),但背景保持透明。
为什么不将运行的背景绑定到资源,就像前景一样???我尝试先将运行和段落添加到FlowDocument,然后进行绑定,但是结果是相同的。
没有找到相关结果
已邀请:
1 个回复
视蕉梁拌客
一个真正的谜是为什么只写\“ ForegroundProperty \”才有效。