c#打印由xaml创建的页面

Kra*_*nys 3 c# printing wpf xaml

正如标题所说,我正在尝试打印由xaml创建的页面(页面看起来像一个表单)

在表单的末尾,我有一个带有事件Click的按钮.

<Button Grid.Row="15" 
    Grid.Column="3"
    Click="ImpressionClick"
    Height="50" 
    Width="150" 
    Grid.RowSpan="2" 
    Grid.ColumnSpan="3" 
    Content="Imprimer">
</Button>
Run Code Online (Sandbox Code Playgroud)

我的问题是:我已经找到了如何使用C#打印一些文本文档,但我不知道如何打印使用xaml代码创建的页面.

如果有人知道如何.

提前致谢.

Florian SELVA

Saj*_*ran 5

使用PrintDialog并传递界面

PrintDialog dialog = new PrintDialog();
dialog.PrintVisual(this.YourLayoutName, "");
Run Code Online (Sandbox Code Playgroud)