数据绑定到 DocumentViewer.Document 属性
我有一个包含 DocumentViewer 控件的视图,并且有另一个类,该类具有公开 FixDocumentSequence 并实现 INotifyPropertyChanged 的属性。我试图将文档查看器的文档属性数据绑定到FixedDocumentSequence 属性,当我运行它时,文档查看器不会加载FixedDocumentSequence。视图中的所有其他绑定均有效,但此绑定无效。
以下是代码片段,如有任何帮助,我们将不胜感激,希望这是我忘记的一些微不足道的事情。
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
}
这是相关的 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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
被调用了吗?尝试返回 IDocumentPaginatorSource。您应该能够将 _fixedDocumentSequence 转换为 IDocumentPaginatorSource。
Is the get called? Try returning IDocumentPaginatorSource. You should be able to cast the _fixedDocumentSequence to IDocumentPaginatorSource.