当绑定源更改时,FlowDocumentReader Document 不会收到通知,为什么?

发布于 2024-07-27 23:47:40 字数 1376 浏览 4 评论 0原文

所以我在 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怼怹恏 2024-08-03 23:47:40

如何实现 WordDocument 属性? 它要么需要是一个依赖属性,要么您需要实现 INotifyPropertyChanged 并在更改属性值时相应地引发 PropertyChanged 事件,或者您需要添加一个 WordDocumentChanged 事件添加到您的类中,并在您更改值时引发该事件。 如果它只是一个普通属性,则绑定表达式无法检测值在运行时何时发生变化。

How do you implement WordDocument property? It either needs to be a dependency property, or you need to implement INotifyPropertyChanged and raise PropertyChanged event accordingly when you change the property value, or you need to add a WordDocumentChanged 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文