How to create win toolkit addons
Private async void PrintHelper_OnPrintSucceeded() PrintHelper.OnPrintSucceeded += PrintHelper_OnPrintSucceeded Īwait printHelper.ShowPrintUIAsync("Windows Community Toolkit Sample App") PrintHelper.OnPrintFailed += PrintHelper_OnPrintFailed PrintHelper.AddFrameworkElementToPrint(await PrepareWebViewForPrintingAsync()) Var printHelper = new PrintHelper(container) It needs to be in your visual tree but can be hidden with Opacity = 0 "container" is a XAML panel that will be used to host printable control. Remove an element from the list of printable elementsĮvent which is called after print preview pages are generatedĮvent raised when print is cancelled by the userĮxample // Create a new PrintHelper instance RemoveFrameworkElementToPrint(FrameworkElement) Gets or sets the percent of app's margin heightĪddFrameworkElementToPrint(FrameworkElement)Īdd an element to the list of printable elements Gets or sets the percent of app's margin width PrintHelper.AddFrameworkElementToPrint(frameworkElement)Īwait printHelper.ShowPrintUIAsync("Title") PrintHelper.AddFrameworkElementToPrint(frameworkElement) Īwait printHelper.ShowPrintUIAsync("Title") ĭim printHelper = New PrintHelper(container) Try it in the sample app Syntax var printHelper = new PrintHelper(container) In this mode you are responsible for the sizing and the layout. You can call ShowPrintUIAsync with a second parameter to determine that the list of controls to print should directly be taken from the content of the container passed to the PrintHelper constructor.
Then, you can use it as a parameter in the PrintHelper class constructor to set them as the default for the instance, or send them as parameters to ShowPrintUIAsync to use them for a single print job.
To use it, create an instance of the class, add the options you'd like to display on the printing dialog and set the default options. In addition, you can customize the printing dialog using the PrintHelperOptions class. This allows you to control the look and feel of your page before they are sent to the spooler. OnPreviewPagesCreated will be triggered after print preview pages are generated.OnPrintSucceeded will be triggered after a successful print.OnPrintFailed will be triggered if the user cancels the print or if something goes wrong.Several events are available to control the printing process:
#How to create win toolkit addons how to
Please check the sample app code to see how to disconnect/reconnect a control that you want to print: If you want to use a control from your current XAML page, you can disconnect it before sending it to print (by removing it from its container) or you can create just create a new one from scratch. This means that their parent property has to be null. Please note that controls cannot be linked to a visual tree. To use it, you only have to instantiate a PrintHelper object and call AddFrameworkElementToPrint method to add the XAML controls you want to print. It allows you to render a framework element per page. The PrintHelper is a class used to simplify document printing.