Databinding to DocumentViewer.Document Property

2019-09-14 02:03发布

问题:

I have a view that contains a DocumentViewer control and I have another class that has a property that exposes a FixedDocumentSequence and implements INotifyPropertyChanged. I am trying to databind the document property of the documentviewer to the FixedDocumentSequence property, when I run it the documentviewer does not load the FixedDocumentSequence. All ofthe other bindings in the view are working but not this one.

Here are the code snippets any help would be appreciated, hopefully it is something trivial that I am forgeting.

public class Generator : INotifyPropertyChanged
{
    private const string _fixedDocumentSequencePropertyName = "Fixed Document Sequence";


    private FixedDocumentSequence _fixedDocumentSequence;
    public FixedDocumentSequence FixedDocumentSeq
    {
        get { return _fixedDocumentSequence; }
        private set
        {
            this._fixedDocumentSequence = value;
            onPropertyChanged(_fixedDocumentSequencePropertyName);
        }
    }

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    private void onPropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

    }

    #endregion
}

and here is the relevant xaml:

<Window.Resources>
    <ResourceDictionary>
    <generator:Generator x:Key="gen"/>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/StyleDictionary.xaml"/>
            <ResourceDictionary Source="Resources/AnimationDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

<Grid DockPanel.Dock="Top" 
          Margin="0,0,0,20" DataContext="{Binding Source={StaticResource gen}}">
        <DocumentViewer Name="documentViewer1" Margin="6,180,8,0" Visibility="Visible" Document="{Binding Path=FixedDocumentSeq, Mode=OneWay}"/>
</Grid>

回答1:

Is the get called? Try returning IDocumentPaginatorSource. You should be able to cast the _fixedDocumentSequence to IDocumentPaginatorSource.