【发布时间】:2012-07-09 14:11:11
【问题描述】:
在previous question 中,我试图从我的 TreeView 打印,现在我转到父视图,我有一个 UserControl 如何包含 TreeView 以在我的 WPFview 上显示我的搜索结果,我尝试打印它,我用 FlowDocumentScrollViewer 包围如下代码:
view.xaml
<FlowDocumentScrollViewer x:Name="flow" Margin="10" BorderThickness="0">
<FlowDocument>
<Section>
<BlockUIContainer>
<my:SearchTreeView Content="{Binding Stvm}"/>
</BlockUIContainer>
</Section>
</FlowDocument>
view.xaml.cs
Printing.PrintDoc( flow.Document, txtSearch.Text + " - Result");
静态打印.cs
public static void PrintDoc(System.Windows.Documents.FlowDocument fd, string description)
{
double h, w, cw;
h = fd.PageHeight ;
w = fd.PageWidth ;
cw = fd.ColumnWidth;
PrintDialog pd = new PrintDialog();
//pd.PageRangeSelection = PageRangeSelection.AllPages;
//pd.UserPageRangeEnabled = true;
if (pd.ShowDialog() != true || fd == null) return;
fd.PageHeight = pd.PrintableAreaHeight;
fd.PageWidth = pd.PrintableAreaWidth;
fd.PagePadding = new Thickness(50);
fd.ColumnGap = 0;
fd.ColumnWidth = pd.PrintableAreaWidth;
System.Windows.Documents.IDocumentPaginatorSource dps = fd;
// int c = dps.DocumentPaginator.PageCount;//0
pd.PrintDocument(dps.DocumentPaginator, description);
fd.PageHeight = h;
fd.PageWidth = w;
fd.PagePadding = new Thickness(0);
fd.ColumnWidth = cw;
}
我尝试了类似问题中的几乎所有示例,但我得到的最好结果只是结果的 首页,例如this.. ;(
我正在使用 WPF MVVM 模式。这是执行此操作的正确控件吗?或者我应该使用任何其他 WPF 控件吗?
【问题讨论】:
-
我在这里回答了一个类似的问题。 stackoverflow.com/questions/6083555/… 谢谢
标签: wpf mvvm printing flowdocumentscrollviewer