How do I apply Transform when an event is occurred ?
Any type of transform can be applied when an event has occurred. The following lines of code apply a ’RotateTransform’ when the mouse is moved over the image. [XAML] <Image Source=’pda.ico’ MouseEnter=’Image_MouseEnter’ MouseLeave=’Image_MouseLeave’> <Image.RenderTransform> <RotateTransform Angle=’0′ x:Name=’ImageRot’/> </Image.RenderTransform> </Image> [C#] private void Image_MouseEnter(object sender, MouseEventArgs e) { ImageRot.Angle = 30; } private void Image_MouseLeave(object sender, MouseEventArgs e) { ImageRot.Angle = 0; }
How do I apply an animation without using a storyboard ?
Animations can be applied without using the StoryBoard. BeginAnimation() method can be used to apply animations instead of StoryBoard. This method can be used when simple animations are applied to a property of a control. The following code snippet animates the width of the TextBlock using the ’BeginAnimation’ method. [C#] DoubleAnimation Dblanimation = new DoubleAnimation(); Dblanimation.From = 25; Dblanimation.To = 50; Dblanimation.Duration = new Duration(TimeSpan.FromSeconds(3)); tb.BeginAnimation(TextBlock.WidthProperty, Dblanimation);
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