/// <summary> /// Loads the component template of the specified control. /// </summary> /// <param name="control">The instance of <see cref="Control"/> for which to load a component root.</param> /// <param name="template">The component template that specifies the control's component layout.</param> /// <returns>The <see cref="UIElement"/> which serves as the specified control's component template.</returns> public static UIElement LoadComponentTemplate(Control control, XDocument template) { Contract.Require(control, nameof(control)); if (template == null) return null; var componentContext = UvmlInstantiationContext.ForControl(control.Ultraviolet, control); var componentTemplate = default(UvmlTemplate); if (!componentTemplateCache.TryGetValue(template, out componentTemplate)) { var componentElement = template.Root.Element("View")?.Elements().SingleOrDefault(); if (componentElement == null) return null; var componentType = default(Type); if (!control.Ultraviolet.GetUI().GetPresentationFoundation().GetKnownType(componentElement.Name.LocalName, out componentType)) throw new UvmlException(PresentationStrings.UnrecognizedType.Format(componentElement.Name.LocalName)); var cultureRequested = (String)template.Root.Attribute("Culture"); var cultureInfo = CultureInfo.GetCultureInfo(cultureRequested ?? String.Empty); AddUvmlAnnotations(componentContext.DataSourceType.Name, componentElement); componentTemplate = CreateTemplateFromXml(control.Ultraviolet, componentElement, control.GetType(), componentType, cultureInfo); componentTemplateCache[template] = componentTemplate; } var componentTemplateInstance = (UvmlTemplateInstance)componentTemplate.Instantiate(control.Ultraviolet, componentContext); var component = (UIElement)componentTemplateInstance.Finalize(); componentContext.Namescope.PopulateFieldsFromRegisteredElements(control); return component; }
/// <summary> /// Loads the component template of the specified control. /// </summary> /// <param name="control">The instance of <see cref="Control"/> for which to load a component root.</param> /// <returns>The <see cref="UIElement"/> which serves as the specified control's component template.</returns> public static UIElement LoadComponentTemplate(Control control) { Contract.Require(control, nameof(control)); var template = control.Ultraviolet.GetUI().GetPresentationFoundation().ComponentTemplates.Get(control); if (template == null) return null; return LoadComponentTemplate(control, template); }
/// <inheritdoc/> protected override void CacheLayoutParametersOverride() { containingControl = FindContainingControl(); DigestDataBoundContentProperties(); base.CacheLayoutParametersOverride(); }
/// <summary> /// Creates an instantiation context for a control. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="control">The control which is being loaded.</param> /// <returns>The instantiation context for the specified control.</returns> public static InstantiationContext FromControl(UltravioletContext uv, Control control) { var wrapper = PresentationFoundation.GetDataSourceWrapper(control); return new InstantiationContext(uv, control, wrapper.GetType()); }
/// <summary> /// Creates an instantiation context for the specified view. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="control">The control for which to create an instantiation context.</param> /// <returns>The instantiation context which was created.</returns> internal static UvmlInstantiationContext ForControl(UltravioletContext uv, Control control) { var wrapper = PresentationFoundation.GetDataSourceWrapper(control); return new UvmlInstantiationContext(uv, control, control, wrapper.GetType(), control.ComponentTemplateNamescope); }