/// <summary> /// When overridden in a derived class, is invoked whenever application code or internal processes (such as a rebuilding layout pass) call <see cref="M:System.Windows.Controls.Control.ApplyTemplate"/>. In simplest terms, this means the method is called just before a UI element displays in an application. For more information, see Remarks. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); var printButton = GetTemplateChild("PART_PrintButton") as Button; //This container must be there because in order to be able to update the layout correctly for the print page it needs to be part of the visual tree. _gridContainer = GetTemplateChild("PART_GridPrintPageContainer") as Grid; _printPage = new PrintPage(); //NOTE:If you do not have the print page be part of the visual tree initially the first print job performed will not update correclty and therefore will not look correct. _gridContainer.Children.Add(_printPage); printButton.Click += PrintButtonClicked; InitializePrintPage(); }
/// <summary> /// When overridden in a derived class, is invoked whenever application code or internal processes (such as a rebuilding layout pass) call <see cref="M:System.Windows.Controls.Control.ApplyTemplate"/>. In simplest terms, this means the method is called just before a UI element displays in an application. For more information, see Remarks. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate (); var printButton = GetTemplateChild ( "PART_PrintButton" ) as Button; //This container must be there because in order to be able to update the layout correctly for the print page it needs to be part of the visual tree. _gridContainer = GetTemplateChild ( "PART_GridPrintPageContainer" ) as Grid; _printPage = new PrintPage (); //NOTE:If you do not have the print page be part of the visual tree initially the first print job performed will not update correclty and therefore will not look correct. _gridContainer.Children.Add ( _printPage ); printButton.Click += PrintButtonClicked; InitializePrintPage (); }