How rendering in WPF differs from WIN32 applications?

A WIN32 application uses immediate mode graphics system wherein the application is responsible for repainting the client area when they are resized or the object’s visual appearance is changed. WPF on the contrary uses retained mode graphics system. In this mode, drawing information of an object is persisted and serialized by the application and the rendering is done by the system.

How can I programmatically print XPS Files ?

You can use one overload of the AddJob() method to print XML Paper Specification (XPS) files without opening a PrintDialog or in principle, any user interface (UI) at all. You can also print XML Paper Specification (XPS) files using the many Write() and WriteAsync() methods of the XPSDocumentWriter. Another way of printing XML Paper Specification (XPS) is to use the PrintDocument() or PrintVisual() methods of the PrintDialog control. The main steps to use the three-parameter AddJob(String, String, Boolean) method are as follows. The example below gives details. 1. Determine if the printer is an XPSDrv printer. 2. The printer is not an XPSDrv printer, set the thread’s apartment to a single thread. 3. Instantiate a print server and print queue object. 4. Call the method specifying a job name, the file to be printed and a Boolean flag indicating whether or not the printer is an XPSDrv printer. [C#] class Program { [System.MTAThreadAttribute()] // Added for clarity, but this line is redundant because MTA is the default. static void Main(string[] args) { // Create the secondary thread and pass the printing method for // the constructor’s ThreadStart delegate parameter. The BatchXPSPrinter // class is defined below. Thread printingThread = new Thread(BatchXPSPrinter.PrintXPS); // Set the thread that will use PrintQueue.AddJob to single threading. printingThread.SetApartmentState(ApartmentState.STA); // Start the printing thread. The method passed to the Thread // constructor will execute. printingThread.Start(); }//end Main }//end Program class public class BatchXPSPrinter { public static void PrintXPS() { // Create print server and print queue. LocalPrintServer localPrintServer = new LocalPrintServer(); PrintQueue defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue(); // Prompt user to identify the directory, and then create the directory object. Console.Write(‘Enter the directory containing the XPS files: ‘); String directoryPath = Console.ReadLine(); DirectoryInfo dir = new DirectoryInfo(directoryPath); // If the user mistyped, end the thread and return to the Main thread. if (!dir.Exists) { Console.WriteLine(‘There is no such directory.’); } else { // If there are no XPS files in the directory, end the thread // and return to the Main thread. if (dir.GetFiles(‘*.xps’).Length == 0) { Console.WriteLine(‘There are no XPS files in the directory.’); } else { Console.WriteLine(‘\nJobs will now be added to the print queue.’); Console.WriteLine(‘If the queue is not paused and the printer is working, jobs will begin printing.’); // Batch process all XPS files in the directory. foreach (FileInfo f in dir.GetFiles(‘*.xps’)) { String nextFile = directoryPath + ‘\\’ + f.Name; Console.WriteLine(‘Adding {0} to queue.’, nextFile); try { // Print the Xps file while providing XPS validation and progress notifications. PrintSystemJobInfo xpsPrintJob = defaultPrintQueue.AddJob(f.Name, nextFile, false); } catch (PrintJobException e) { Console.WriteLine(‘\n\t{0} could not be added to the print queue.’, f.Name); if (e.InnerException.Message == ‘File contains corrupted data.’) { Console.WriteLine(‘\tIt is not a valid XPS file. Use the isXPS Conformance Tool to debug it.’); } Console.WriteLine(‘\tContinuing with next XPS file.\n’); } }// end for each XPS file }//end if there are no XPS files in the directory }//end if the directory does not exist Console.WriteLine(‘Press Enter to end program.’); Console.ReadLine(); }// end PrintXPS method }// end BatchXPSPrinter class

How can I diagnose a problematic Print Job ?

The example code begins by refreshing the current print queue object with PrintQueue’s Refresh property. This ensures that the object’s properties accurately represent the state of the physical printer that it represents. Then the application gets the collection of print jobs currently in the print queue by using the “GetPrintJobInfoCollection” method. Next the application loops through the PrintSystemJobInfo collection and compares each ’Submitter’ property with the alias of the complaining user. If they match, the application adds identifying information about the job to the string that will be presented. (The userName and jobList variables are initialized earlier in the application.) [C#] foreach (PrintQueue pq in myPrintQueues) { pq.Refresh(); PrintJobInfoCollection jobs = pq.GetPrintJobInfoCollection(); foreach (PrintSystemJobInfo job in jobs) { // Since the user may not be able to articulate which job is problematic, // present information about each job the user has submitted. if (job.Submitter == userName) { atLeastOne = true; jobList = jobList + ‘\nServer:’ + line; jobList = jobList + ‘\n\tQueue:’ + pq.Name; jobList = jobList + ‘\n\tLocation:’ + pq.Location; jobList = jobList + ‘\n\t\tJob: ‘ + job.JobName + ‘ ID: ‘ + job.JobIdentifier; } }// end for each print job }// end for each print queue

How can I clone a printer ?

In the example below, a second print queue is cloned from an existing print queue. The second differs from the first only in its name, location, port, and shared status. The major steps for doing this are as follows. [C#] LocalPrintServer myLocalPrintServer = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer); PrintQueue sourcePrintQueue = myLocalPrintServer.DefaultPrintQueue; PrintPropertyDictionary myPrintProperties = sourcePrintQueue.PropertiesCollection; // Share the new printer using Remove/Add methods PrintBooleanProperty shared = new PrintBooleanProperty(‘IsShared’, true); myPrintProperties.Remove(‘IsShared’); myPrintProperties.Add(‘IsShared’, shared); // Give the new printer its share name using SetProperty method PrintStringProperty theShareName = new PrintStringProperty(‘ShareName’, ‘\’Son of ‘ + sourcePrintQueue.Name +’\”); myPrintProperties.SetProperty(‘ShareName’, theShareName); // Specify the physical location of the new printer using Remove/Add methods PrintStringProperty theLocation = new PrintStringProperty(‘Location’, ‘the supply room’); myPrintProperties.Remove(‘Location’); myPrintProperties.Add(‘Location’, theLocation); // Specify the port for the new printer String[] port = new String[] { ‘COM1:’ }; // Install the new printer on the local print server PrintQueue clonedPrinter = myLocalPrintServer.InstallPrintQueue(‘My clone of ‘ + sourcePrintQueue.Name, ‘Xerox WCP 35 PS’, port, ‘WinPrint’, myPrintProperties); myLocalPrintServer.Commit(); // Report outcome Console.WriteLine(‘{0} in {1} has been installed and shared as {2}’, clonedPrinter.Name, clonedPrinter.Location, clonedPrinter.ShareName); Console.WriteLine(‘Press Return to continue …’); Console.ReadLine();

Can I embed a figure into a paragraph of text ?

Figure and Floater are used to embed content in Flow Documents with placement properties that can be customized independent of the primary content flow. Figure or Floater elements are often used to highlight or accentuate portions of content to host supporting images or other content within the main content flow or to inject loosely related content such as advertisements. The following example shows how to embed a Figure into a paragraph of text. [XAML] <FlowDocument xmlns=’http://schemas.microsoft.com/winfx/2006/xaml/presentation’ xmlns:x=’http://schemas.microsoft.com/winfx/2006/xaml’> <Paragraph> <Figure Width=’300′ Height=’100′ Background=’GhostWhite’ HorizontalAnchor=’PageLeft’ > <Paragraph FontStyle=’Italic’ Background=’Beige’ Foreground=’DarkGreen’ > A Figure embeds content into flow content with placement properties that can be customized independently from the primary content flow </Paragraph> </Figure> </Paragraph> </FlowDocument>