代码之家  ›  专栏  ›  技术社区  ›  Vin

当绑定源更改时,不会通知FlowDocumentReader文档,为什么?

  •  0
  • Vin  · 技术社区  · 17 年前

    所以我在.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");
            }
     }
    

    单击按钮,我将更改Word文档的内容。CreateFlowDocument创建一个段落和一个传递字符串的运行。

    单击按钮时,虽然我已将其绑定到WordDocument属性,但FlowDocumentReader不会显示更改的内容。

    我做错什么了?

    1 回复  |  直到 17 年前
        1
  •  1
  •   Pavel Minaev    17 年前

    你如何实施 WordDocument 财产?它要么需要是依赖属性,要么需要实现 INotifyPropertyChanged 并提高 PropertyChanged 当您更改属性值或需要添加 WordDocumentChanged 事件并在更改值时将其提高。如果它只是一个普通属性,那么绑定表达式就无法检测值在运行时的变化。

    推荐文章