/// <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(); this.grid = this.GetTemplateChild(PartGrid) as Grid; if (this.grid == null) { return; } this.canvas = new Canvas(); this.grid.Children.Add(this.canvas); this.canvas.UpdateLayout(); this.renderContext = new PhoneRenderContext(this.canvas); this.overlays = new Canvas(); this.grid.Children.Add(this.overlays); this.zoomControl = new ContentControl(); this.overlays.Children.Add(this.zoomControl); }