Есть WPF приложение, в одном из окон есть контрол DocumentViewer, в котором отображается сгенерированный отчет.
Для печати вызываю подобный код:
1.
2.
3.
4.
5.
6.
7.
private void PrintSelectedReportExecute()
{
var printDialog = new PrintDialog();
bool? printDialogResult = printDialog.ShowDialog();
if (printDialogResult != null && (bool)printDialogResult)
printDialog.PrintDocument(printPreviewWindowViewModel.Document.DocumentPaginator, "NameOfReport");
}
Открывается диалог печати из которого уже пользователь отправляет на нужный принтер печать отчета.
Все работает ормально. Единственное в чем возникла необходимость это сделать так что, окно диалога печати (printDialog)
было окном поверх всех окон (Topmost = true).
Сам системный класс PrintDialog определен след. образом:
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.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
using System.Printing;
using System.Security;
using System.Windows.Documents;
using System.Windows.Documents.Serialization;
using System.Windows.Media;
namespace System.Windows.Controls
{
// Summary:
// Invokes a standard Microsoft Windows print dialog box that configures a System.Printing.PrintTicket
// and System.Printing.PrintQueue according to user input and then prints a
// document.
public class PrintDialog
{
// Summary:
// Initializes a new instance of the System.Windows.Controls.PrintDialog class.
[SecurityCritical]
public PrintDialog();
// Summary:
// Gets or sets the highest page number that is allowed in page ranges.
//
// Returns:
// A System.UInt32 that represents the highest page number that can be used
// in a page range in the Print dialog box.
//
// Exceptions:
// System.ArgumentException:
// The property is being set to less than 1.
public uint MaxPage { get; set; }
//
// Summary:
// Gets or sets the lowest page number that is allowed in page ranges.
//
// Returns:
// A System.UInt32 that represents the lowest page number that can be used in
// a page range in the Print dialog box.
//
// Exceptions:
// System.ArgumentException:
// The property is being set to less than 1.
public uint MinPage { get; set; }
//
// Summary:
// Gets or sets the range of pages to print when System.Windows.Controls.PrintDialog.PageRangeSelection
// is set to System.Windows.Controls.PageRangeSelection.UserPages.
//
// Returns:
// A System.Windows.Controls.PageRange that represents the range of pages that
// are printed.
//
// Exceptions:
// System.ArgumentException:
// The System.Windows.Controls.PageRange object that is being used to set the
// property has either the beginning of the range or the end of the range set
// to a value that is less than 1.
public PageRange PageRange { get; set; }
//
// Summary:
// Gets or sets the System.Windows.Controls.PageRangeSelection for this instance
// of System.Windows.Controls.PrintDialog.
//
// Returns:
// The System.Windows.Controls.PageRangeSelection value that represents the
// type of page range to print.
public PageRangeSelection PageRangeSelection { get; set; }
//
// Summary:
// Gets the height of the printable area of the page.
//
// Returns:
// A System.Double that represents the height of the printable page area.
public double PrintableAreaHeight { get; }
//
// Summary:
// Gets the width of the printable area of the page.
//
// Returns:
// A System.Double that represents the width of the printable page area.
public double PrintableAreaWidth { get; }
//
// Summary:
// Gets or sets a System.Printing.PrintQueue that represents the printer that
// is selected.
//
// Returns:
// The System.Printing.PrintQueue that the user selected.
public System.Printing.PrintQueue PrintQueue { get; set; }
//
// Summary:
// Gets or sets the System.Printing.PrintTicket that is used by the System.Windows.Controls.PrintDialog
// when the user clicks Print for the current print job.
//
// Returns:
// A System.Printing.PrintTicket that is used the next time the Print button
// in the dialog box is clicked. Setting this System.Windows.Controls.PrintDialog.PrintTicket
// property does not validate or modify the specified System.Printing.PrintTicket
// for a particular System.Printing.PrintQueue. If needed, use the System.Printing.PrintQueue.MergeAndValidatePrintTicket(System.Printing.PrintTicket,System.Printing.PrintTicket)
// method to create a System.Printing.PrintQueue-specific System.Printing.PrintTicket
// that is valid for a given printer.
public PrintTicket PrintTicket { get; set; }
//
// Summary:
// Gets or sets a value that indicates whether users of the Print dialog box
// have the option to specify ranges of pages to print.
//
// Returns:
// true if the option is available; otherwise, false.
public bool UserPageRangeEnabled { get; set; }
// Summary:
// Prints a System.Windows.Documents.DocumentPaginator object to the System.Printing.PrintQueue
// that is currently selected.
//
// Parameters:
// documentPaginator:
// The System.Windows.Documents.DocumentPaginator object to print.
//
// description:
// A description of the job that is to be printed. This text appears in the
// user interface (UI) of the printer.
//
// Exceptions:
// System.ArgumentNullException:
// documentPaginator is null.
[SecurityCritical]
public void PrintDocument(DocumentPaginator documentPaginator, string description);
//
// Summary:
// Prints a visual (non-text) object, which is derived from the System.Windows.Media.Visual
// class, to the System.Printing.PrintQueue that is currently selected.
//
// Parameters:
// visual:
// The System.Windows.Media.Visual to print.
//
// description:
// A description of the job that is to be printed. This text appears in the
// user interface (UI) of the printer.
//
// Exceptions:
// System.ArgumentNullException:
// visual is null.
[SecurityCritical]
public void PrintVisual(Visual visual, string description);
//
// Summary:
// Invokes the System.Windows.Controls.PrintDialog as a modal dialog box.
//
// Returns:
// true if a user clicks Print; false if a user clicks Cancel; or null if a
// user closes the dialog box without clicking Print or Cancel.
[SecurityCritical]
public bool? ShowDialog();
}
}
Т.е. это просто класс, где-то внутри себе создаюший окно, но насколько я понял не возвращаюший ссылку непосредственно на окно.
Как сделать так чтоб окно диалога печати (PrintDialog) было окном поверх всех окон (Topmost = true)?