blob: 0728c84ce9aabdb41c544143f20a9da456eb1f06 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved
//
//
// Abstract:
//
// This file contains as the interaction logic for ValidationModaldialog.
// This dialog prevents the user from making changes to print ticket settings when asynchronous
// validation is being performed.
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Microsoft.Samples.Printing.PrinterExtension.Types;
namespace Microsoft.Samples.Printing.PrinterExtension
{
/// <summary>
/// Interaction logic for ValidationModalDialog.xaml
/// This dialog prevents the user from changing print preferences when validation is in progress.
/// </summary>
public partial class ValidationModalDialog : UserControl
{
public ValidationModalDialog()
{
InitializeComponent();
Visibility = Visibility.Hidden;
}
/// <summary>
/// Starts the asynchronous operation.
/// </summary>
/// <param name="asyncOperationToStart">Async operation context.</param>
public void StartAsyncOperation(IPrintSchemaAsyncOperation asyncOperationToStart)
{
this.asyncOperationContext = asyncOperationToStart;
Visibility = Visibility.Visible;
asyncOperationToStart.Completed += asyncOperation_Completed;
asyncOperationToStart.Start();
}
/// <summary>
/// This method is invoked from a different thread once asynchronous validation is completed.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void asyncOperation_Completed(object sender, PrintSchemaAsyncOperationEventArgs e)
{
ValidationHResult = e.StatusHResult;
HideWindow();
if (Completed != null)
{
Completed(this, e);
}
}
/// <summary>
/// Hides the current window.
/// </summary>
private void HideWindow()
{
this.Dispatcher.Invoke(new Action(() =>
{
Visibility = Visibility.Hidden;
}));
}
/// <summary>
/// Result of the validation operation.
/// </summary>
public int ValidationHResult
{
get;
private set;
}
/// <summary>
/// Invoked then the "Cancel" button is clicked.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CancelValidationButton_Click(object sender, RoutedEventArgs e)
{
asyncOperationContext.Cancel();
HideWindow();
}
/// <summary>
/// Invoked when the asynchronous operation is completed.
/// </summary>
public event EventHandler<PrintSchemaAsyncOperationEventArgs> Completed;
/// <summary>
/// Asynchronous operation context.
/// </summary>
private IPrintSchemaAsyncOperation asyncOperationContext;
}
}
|