1
不顯示
我創建了一個自定義文檔分頁程序,需要一個數據表並打印正是我所需要的。我想做一個打印預覽。我已閱讀如何在內存中創建一個XPS文件的所有帖子,然後顯示它。我只是無法讓它工作。這是我的代碼。我正在使用MVVM模式。請注意代碼_data.DocView = FDS線;這將數據傳遞給我的視圖模型。打印預覽中的DocumentViewer
PrintDialog dialog = new PrintDialog();
dialog.ShowDialog();
StoreDataSetPaginator paginator = new StoreDataSetPaginator(dt, new Typeface("Calibri"), 8, 96 * 0.75,
new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight));
//this is commented out to attempt the print preview
// dialog.PrintDocument(paginator, "Print out");
MemoryStream ms = new MemoryStream();
Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);
Uri DocumentUri = new Uri("pack://InMemoryDocument.xps");
PackageStore.AddPackage(DocumentUri, package);
XpsDocument xpsDocument = new XpsDocument(package, CompressionOption.NotCompressed,
DocumentUri.AbsoluteUri);
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
writer.Write(paginator);
IDocumentPaginatorSource fds = xpsDocument.GetFixedDocumentSequence();
_data.DocView = fds;
PrintPreviewConduit prntv = new PrintPreviewConduit();
prntv.Show();
現在,這裏是我的視圖模型:
private IDocumentPaginatorSource _docView;
public IDocumentPaginatorSource DocView
{
get { return _docView; }
set
{
_docView = value;
OnPropertyChanged("DocView");
}
}
最後我的XAML:
<Grid>
<DocumentViewer Name="docview" Document="{Binding DocView}"/>
</Grid>
我在 「公共IDocumentPaginatorSource DocView」,當我進入我的ViewModel一個破發點卷我鼠標移到它,我得到「System.Windows.Documents.FixedDocumentSequence。不知道我應該得到。我花了好一段時間,現在和任何幫助將不勝感激。 Sys系統