【发布时间】:2013-01-29 10:18:06
【问题描述】:
我正在使用 Lightswitch 编写 Silverlight 应用程序。我想打印某些屏幕上显示的数据。
我发现this tutorial 用于在 Silverlight/Lightswitch 中打印。它描述了如何使用可以打印的 XAML 创建自定义控件。控件如下所示:
在后台,您可以看到控件在 Silverlight 应用程序中的外观。该控件同时包含一个按钮和一个网格:
<StackPanel>
<Button Content="Print" Name="btnPrint" Click="btnPrint_Click" />
<Grid x:Name="LayoutRoot">
<!-- grid code goes here -->
<!-- some more code an closing tags -->
使用 Silverlight 的打印 API,在自定义控件中进行如下打印:
PrintDocument printInvoice = new PrintDocument();
private void btnPrint_Click(object sender, System.Windows.RoutedEventArgs e){
printInvoice.PrintPage +=
new EventHandler<PrintPageEventArgs>(printInvoice_PrintPage);
}
void printInvoice_PrintPage(object sender, PrintPageEventArgs e){
e.PageVisual = LayoutRoot;
}
由于使用了e.PageVisual = LayoutRoot,我们在打印输出中只看到表格,而不是按钮。没关系,但我想为打印布局使用单独的 XAML。我的目标是仅在 Silverlight 应用程序上显示一个按钮 Print,并在单独的 XAML 中定义打印布局。
所以,我刚刚开始创建第二个 XAML 作为 SilverlightControl 并尝试使用它:
MyPrintLayout mpl = new MyPrintLayout();
void printArtikels_PrintPage(object sender, PrintPageEventArgs e){
e.PageVisual = mpl.LayoutRoot;
}
但我收到错误“Das Element ist bereits das untergeordnete Element eines anderen Elements”(英文:“该元素已经是另一个元素的子元素”)。 this question 也讨论了这个错误,但它并没有解决我的问题。
当我在 silverlight 应用程序中包含 MyPrintLayout 时,它会毫无问题地显示(其中只有一些文本用于测试功能)。
看来我这样做完全错了。我怎样才能实现我的目标?
【问题讨论】:
-
@memorizer 我看到你已经回答了我的问题,为什么这个帖子现在被删除了?它解决了我的问题,只是想接受它......
-
抱歉,点击了错误的链接... =)
标签: c# silverlight xaml printing visual-studio-lightswitch