--- title: "How to: Validate and Merge PrintTickets" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "merging PrintTickets [WPF]" - "PrintTicket [WPF], merging" - "validation of PrintTickets [WPF]" - "PrintTicket [WPF], validation" ms.assetid: 4fe2d501-d0b0-4fef-86af-6ffe6c162532 --- # How to: Validate and Merge PrintTickets The Microsoft Windows [Print Schema](/windows/win32/printdocs/printschema) includes the flexible and extensible and elements. The former itemizes the capabilities of a print device and the latter specifies how the device should use those capabilities with respect to a particular sequence of documents, individual document, or individual page. A typical sequence of tasks for an application that supports printing would be as follows. 1. Determine a printer's capabilities. 2. Configure a to use those capabilities. 3. Validate the . This article shows how to do this. ## Example In the simple example below, we are interested only in whether a printer can support duplexing — two-sided printing. The major steps are as follows. 1. Get a object with the method. 2. Test for the presence of the capability you want. In the example below, we test the property of the object for the presence of the capability of printing on both sides of a sheet of paper with the "page turning" along the long side of the sheet. Since is a collection, we use the `Contains` method of . > [!NOTE] > This step is not strictly necessary. The method used below will check each request in the against the capabilities of the printer. If the requested capability is not supported by printer, the printer driver will substitute an alternative request in the returned by the method. 3. If the printer supports duplexing, the sample code creates a that asks for duplexing. But the application does not specify every possible printer setting available in the element. That would be wasteful of both programmer and program time. Instead, the code sets only the duplexing request and then merges this with an existing, fully configured and validated, , in this case, the user's default . 4. Accordingly, the sample calls the method to merge the new, minimal, with the user's default . This returns a that includes the new as one of its properties. 5. The sample then tests that the new requests duplexing. If it does, then the sample makes it the new default print ticket for the user. If step 2 above had been left out and the printer did not support duplexing along the long side, then the test would have resulted in `false`. (See the note above.) 6. The last significant step is to commit the change to the property of the with the method. [!code-csharp[PrintTicketManagment#UsingMergeAndValidate](~/samples/snippets/csharp/VS_Snippets_Wpf/PrintTicketManagment/CSharp/printticket.cs#usingmergeandvalidate)] [!code-vb[PrintTicketManagment#UsingMergeAndValidate](~/samples/snippets/visualbasic/VS_Snippets_Wpf/PrintTicketManagment/visualbasic/printticket.vb#usingmergeandvalidate)] So that you can quickly test this example, the remainder of it is presented below. Create a project and a namespace and then paste both the code snippets in this article into the namespace block. [!code-csharp[PrintTicketManagment#UIForMergeAndValidatePTUtility](~/samples/snippets/csharp/VS_Snippets_Wpf/PrintTicketManagment/CSharp/printticket.cs#uiformergeandvalidateptutility)] [!code-vb[PrintTicketManagment#UIForMergeAndValidatePTUtility](~/samples/snippets/visualbasic/VS_Snippets_Wpf/PrintTicketManagment/visualbasic/printticket.vb#uiformergeandvalidateptutility)] ## See also - - - - - - - - [Documents in WPF](documents-in-wpf.md) - [Printing Overview](printing-overview.md) - [Print Schema](/windows/win32/printdocs/printschema)