protected void SetTemplateControl(FrameworkElement templateControl) { FrameworkElement oldTemplateControl = _templateControl; if (ReferenceEquals(oldTemplateControl, templateControl)) { return; } _templateControl = null; if (oldTemplateControl != null) { oldTemplateControl.CleanupAndDispose(); } if (templateControl == null) { return; } object content = _convertedContent; if (!(content is FrameworkElement)) // If our content is a FrameworkElement itself, it should only be used as template control but not as context { templateControl.Context = content; } templateControl.LogicalParent = this; templateControl.VisualParent = this; templateControl.SetScreen(Screen); templateControl.SetElementState(_elementState); if (IsAllocated) { templateControl.Allocate(); } _templateControl = templateControl; InvalidateLayout(true, true); }
void OnTemplateControlChanged(AbstractProperty property, object oldValue) { FrameworkElement oldTemplateControl = oldValue as FrameworkElement; MPF.TryCleanupAndDispose(oldTemplateControl); FrameworkElement element = TemplateControl; if (element != null) { element.VisualParent = this; element.SetScreen(Screen); element.SetElementState(_elementState); if (element.TemplateNameScope == null) { // This might be the case if the TemplateControl is directly assigned, without the use of a FrameworkTemplate, // which normally sets the TemplateNameScope. element.TemplateNameScope = new NameScope(); } if (IsAllocated) { element.Allocate(); } } _initializedTemplateControl = element; InvalidateLayout(true, true); }
protected void PrepareVisual() { FrameworkElement visual = Visual; if (_preparedVisual != null && _preparedVisual != visual) { _preparedVisual.SetElementState(ElementState.Available); _preparedVisual.Deallocate(); _preparedVisual = null; } if (_screen == null) { return; } if (visual == null) { return; } if (AutoLayoutContent) { // We must bypass normal layout or the visual will be layed out to screen/skin size visual.SetScreen(_screen); if (visual.ElementState == ElementState.Available) { visual.SetElementState(ElementState.Running); } // Here is _screen != null, which means we are allocated visual.Allocate(); SizeF size = _vertsBounds.Size; visual.Measure(ref size); visual.Arrange(new RectangleF(0, 0, _vertsBounds.Size.Width, _vertsBounds.Size.Height)); } _preparedVisual = visual; }
public void SetKeyboardLayoutControl(VirtualKeyboardControl parent, FrameworkElement keyboardLayoutControl) { FrameworkElement oldKeyboardControl = _keyboardLayoutControl; _keyboardLayoutControl = null; if (oldKeyboardControl != null) { oldKeyboardControl.CleanupAndDispose(); } if (keyboardLayoutControl == null) { return; } keyboardLayoutControl.Context = parent; keyboardLayoutControl.LogicalParent = this; keyboardLayoutControl.VisualParent = this; keyboardLayoutControl.SetScreen(Screen); keyboardLayoutControl.SetElementState(_elementState); if (IsAllocated) { keyboardLayoutControl.Allocate(); } _keyboardLayoutControl = keyboardLayoutControl; InvalidateLayout(true, true); }
public override void Allocate() { base.Allocate(); FrameworkElement fe = _preparedVisual; if (fe != null) { fe.Allocate(); } }