在c#XAML应用程序中进行简单打印?

在c#XAML应用程序中进行简单打印?,c#,xaml,windows-8,C#,Xaml,Windows 8,因此,我需要从Windows8应用程序(c#Xaml)打印一个标签,我发现的所有示例都过于复杂,无法满足我的需要。 我的内容是一个单独的页面,包含一个文本块和一个图像,在页面加载时填充,我所需要做的就是打印该页面。是否有一种简单的打印方法(即不使用RichTextBox和Overflows等)来打印单个简单页面。对于感兴趣的人,这是我需要打印的页面: <Page x:Class="Storeageapp.OutputforLabel" xmlns="http://schemas.micro

因此,我需要从Windows8应用程序(c#Xaml)打印一个标签,我发现的所有示例都过于复杂,无法满足我的需要。 我的内容是一个单独的页面,包含一个文本块和一个图像,在页面加载时填充,我所需要做的就是打印该页面。是否有一种简单的打印方法(即不使用RichTextBox和Overflows等)来打印单个简单页面。对于感兴趣的人,这是我需要打印的页面:

<Page
x:Class="Storeageapp.OutputforLabel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Storeageapp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Width="300" Height="200">
<Grid x:Name="printableArea">

    <Grid.RowDefinitions>

        <RowDefinition Height="3*"/>
        <RowDefinition Height="3*"/>

    </Grid.RowDefinitions>


    <StackPanel x:Name="header" Grid.Row="0" Grid.ColumnSpan="2" Height="60"  Visibility="Collapsed">

    </StackPanel>

    <TextBlock x:Name="UID" Text="Hello World" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24" />

    <Image Source="" x:Name="scenarioImage"  HorizontalAlignment="Center" Grid.Row="1" Grid.Column="0" Margin="10"/>

    <StackPanel x:Name="footer"  Grid.Row="4" Grid.Column="0" VerticalAlignment="Top" Visibility="Collapsed">

    </StackPanel>
</Grid>
</Page>

如果有办法把它打印成图片,我会很高兴,但我想不出来。 谢谢
编辑:这是在windows应用商店应用程序中,抱歉,不是WPF。

您可以使用在WPF中执行基本打印。根据链接页面中的示例:

private void InvokePrint(object sender, RoutedEventArgs e)
{
    // Create the print dialog object and set options
    PrintDialog pDialog = new PrintDialog();
    pDialog.PageRangeSelection = PageRangeSelection.AllPages;
    pDialog.UserPageRangeEnabled = true;

    // Display the dialog. This returns true if the user presses the Print button.
    Nullable<Boolean> print = pDialog.ShowDialog();
    if (print == true)
    {
        XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
        FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
        pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
    }
}

抱歉,我使用的是Windows应用商店应用程序,不是WPF。@Sheridan。好例子-谢谢分享。它在我的WPF项目中帮助了我很多+1.
PrintDialog printDialog = new PrintDialog();
document.ColumnWidth = printDialog.PrintableAreaWidth;
if (printDialog.ShowDialog() == true) printDialog.PrintDocument(
    ((IDocumentPaginatorSource)document).DocumentPaginator, "Flow Document Print Job");