当绑定源更改时,FlowDocumentReader Document 不会收到通知,为什么?
所以我在 .xaml 文件中有这个 XAML
<StackPanel>
<Button Width="200" Height="30" Content="Change Words"
Click="Button_Click"/>
<FlowDocumentReader
ViewingMode="Scroll" Zoom="90"
Focusable="True"
Background="White"
IsFindEnabled="True"
IsPageViewEnabled="True"
IsScrollViewEnabled="True"
x:Name="FDR"
Document="{Binding Path=WordDocument}"
Width="400" Height="400">
</FlowDocumentReader>
</StackPanel>
在后面的代码中, 加载时,
public partial class Window1 : Window
{
MyDoc _myDoc = null;
FlowDocument _theFlowDocument;
public Window1()
{
InitializeComponent();
_myDoc = new MyDoc().Create(); // Create returns MyDoc, that has a WordDocument property with some FlowDocument contents
this.DataContext = _myDoc ;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
_myDoc.WordDocument = _myDoc.CreateFlowDocument("Now it's changed");
}
}
单击按钮时,我正在更改 WordDocument 的内容。 CreateFlowDocument 使用传递的字符串创建一个 Paragraph 和一个 Run。
单击按钮时,FlowDocumentReader 不显示更改的内容,尽管我已将其绑定到 WordDocument 属性
我做错了什么?
So I have this XAML in the .xaml file
<StackPanel>
<Button Width="200" Height="30" Content="Change Words"
Click="Button_Click"/>
<FlowDocumentReader
ViewingMode="Scroll" Zoom="90"
Focusable="True"
Background="White"
IsFindEnabled="True"
IsPageViewEnabled="True"
IsScrollViewEnabled="True"
x:Name="FDR"
Document="{Binding Path=WordDocument}"
Width="400" Height="400">
</FlowDocumentReader>
</StackPanel>
And in the code behind,
On load,
public partial class Window1 : Window
{
MyDoc _myDoc = null;
FlowDocument _theFlowDocument;
public Window1()
{
InitializeComponent();
_myDoc = new MyDoc().Create(); // Create returns MyDoc, that has a WordDocument property with some FlowDocument contents
this.DataContext = _myDoc ;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
_myDoc.WordDocument = _myDoc.CreateFlowDocument("Now it's changed");
}
}
On button click, I am changing the contents of the WordDocument. The CreateFlowDocument creates a Paragraph and a Run with the string passed.
When button is clicked, the FlowDocumentReader doesn't show the changed contents, although I've bound it to the WordDocument property
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何实现
WordDocument
属性? 它要么需要是一个依赖属性,要么您需要实现 INotifyPropertyChanged 并在更改属性值时相应地引发PropertyChanged 事件,或者您需要添加一个
WordDocumentChanged
事件添加到您的类中,并在您更改值时引发该事件。 如果它只是一个普通属性,则绑定表达式无法检测值在运行时何时发生变化。How do you implement
WordDocument
property? It either needs to be a dependency property, or you need to implementINotifyPropertyChanged
and raisePropertyChanged
event accordingly when you change the property value, or you need to add aWordDocumentChanged
event to your class and raise that when you change the value. If it's just a plain property, there's no way for binding expression to detect when the value changes at run-time.