使用DocumentViewer在MVVM Light中查看.docx文档
本文关键字:docx 文档 Light DocumentViewer MVVM 使用 | 更新日期: 2023-09-27 18:04:53
我有一个发射的relaycommand,我试图设置DocumentViewer在MVVM中显示文档当这样做是WPF这是相当直接的,但我必须在视图模型中这样做。使用下面的代码目前没有任何事情发生....
XAML Code:<DocumentViewer HorizontalAlignment="Left" Margin="30,10,0,0"
Name="documentViewer1" VerticalAlignment="Top" Height="200" Width="600" />
ViewModel Code:
private void FileChooser()
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.DefaultExt = ".docx";
dlg.Filter = ".Docx Files (*.docx)|*.docx";
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
string fileName = dlg.FileName;
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
string newXPSDocumentName = String.Concat(System.IO.Path.GetDirectoryName(dlg.FileName), "''",
System.IO.Path.GetFileNameWithoutExtension(dlg.FileName), ".xps");
DocText = ConvertWordDocToXPSDoc(dlg.FileName, newXPSDocumentName).GetFixedDocumentSequence();
}
}
DocumentViewer视图模型中的PropertyChangedMethod:
private IDocumentPaginatorSource _docText;
public IDocumentPaginatorSource DocText
{
get
{
return _docText;
}
set
{
_docText = value;
RaisePropertyChanged("DocText");
}
}
没有显示任何文档,也没有错误,请帮助。
作为对我的问题的回答和当你累了编码的警告....当我回过头来查看我的代码时,问题出在我的xaml上,因为我忘了绑定我的逻辑。总是小事情....所以正确的xaml应该是:
<DocumentViewer HorizontalAlignment="Left" Margin="30,10,0,0"
Document="{Binding Path=DocText, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Height="200" Width="600" />