我有一个 Metro 应用程序,想检测打印机魅力何时打开和关闭。这可能吗?
问问题
527 次
1 回答
1
您可以使用PrintManager
'PrintTaskRequested
事件。打开打印机超级按钮栏时,会发生该事件。PrintTaskRequested
事件使用PrintTask
对象进行打印。它有一个称为Completed
事件的事件。它在打印任务完成时发生。
PrintTask类的 MSDN 文档
PrintManager类的 MSDN 文档
XAML
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Button Click="Button_Click_1" Content="Print" />
</Grid>
C#
public sealed partial class BlankPage2 : Page
{
public BlankPage2()
{
this.InitializeComponent();
PrintManager printMan = PrintManager.GetForCurrentView();
printMan.PrintTaskRequested += PrintTaskRequested;
}
private void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("Printer Opened");
//TODO:
PrintTask printTask = e.Request.CreatePrintTask(....);
printTask.Completed += printTask_Completed;
}
void printTask_Completed(PrintTask sender, PrintTaskCompletedEventArgs args)
{
//TODO:
}
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
await Windows.Graphics.Printing.PrintManager.ShowPrintUIAsync();
}
}
于 2013-05-01T07:44:31.943 回答