C# 如何从WPF窗口stackpanel中打印

C# 如何从WPF窗口stackpanel中打印,c#,wpf,C#,Wpf,我有一个WPF Windows应用程序。在一个窗口中有一个特定的stackpanel,它保存着一些用户数据 我只想把这个stackpanel打印出来 请建议?如果您的StackPanel被称为“ui\u StackPanel”,并且您有一个名为“ui\u print”的按钮,带有相应的点击事件: private void ui_print_Click(object sender, RoutedEventArgs e) { PrintDialog printDial

我有一个WPF Windows应用程序。在一个窗口中有一个特定的stackpanel,它保存着一些用户数据

我只想把这个stackpanel打印出来


请建议?

如果您的
StackPanel
被称为“ui\u StackPanel”,并且您有一个名为“ui\u print”的按钮,带有相应的点击事件:

    private void ui_print_Click(object sender, RoutedEventArgs e)
    {
        PrintDialog printDialog = new PrintDialog();
        if (printDialog.ShowDialog() == true)
        {
            printDialog.PrintVisual(ui_stackPanel, "Stack panel description");
        }
    }

打印的内容远不止这些,这将简单地打印屏幕上的视觉效果。但是这应该可以让您开始了。

如果您的
StackPanel
被称为“ui\u StackPanel”,并且您有一个名为“ui\u print”的按钮,其中有一个相应的点击事件:

    private void ui_print_Click(object sender, RoutedEventArgs e)
    {
        PrintDialog printDialog = new PrintDialog();
        if (printDialog.ShowDialog() == true)
        {
            printDialog.PrintVisual(ui_stackPanel, "Stack panel description");
        }
    }
打印的内容远不止这些,这将简单地打印屏幕上的视觉效果。但这应该让你开始