public AssetCompositeHierarchyData <UIElementDesign, UIElement> Create(UIAssetBase targetAsset) { if (!library.Asset.Hierarchy.Parts.ContainsKey(Id)) { throw new InvalidOperationException("The corresponding UI Element could not be found in the library"); } var asset = (UILibraryAsset)library.Asset; return(asset.CreateElementInstance(targetAsset, library.Url, Id)); }
public AssetCompositeHierarchyData <UIElementDesign, UIElement> Create(UIAssetBase targetAsset) { // Create a clone without linking to the library var flags = SubHierarchyCloneFlags.GenerateNewIdsForIdentifiableObjects | SubHierarchyCloneFlags.RemoveOverrides; var clonedHierarchy = UIAssetPropertyGraph.CloneSubHierarchies(library.Session.AssetNodeContainer, library.Asset, id.Yield(), flags, out Dictionary <Guid, Guid> _); foreach (var part in clonedHierarchy.Parts.Values) { // Reset name property part.UIElement.Name = null; part.Base = null; } return(clonedHierarchy); }
private static IEnumerable <UIElementDesign> GetOrCreateChildPartDesigns([NotNull] UIAssetBase asset, [NotNull] UIElementDesign partDesign) { var assetControl = (ContentControl)partDesign.UIElement; if (assetControl.Content != null) { if (!asset.Hierarchy.Parts.TryGetValue(assetControl.Content.Id, out UIElementDesign elementDesign)) { elementDesign = new UIElementDesign(assetControl.Content); } if (assetControl.Content != elementDesign.UIElement) { throw new InvalidOperationException(); } yield return(elementDesign); } }
private static IEnumerable <UIElementDesign> GetOrCreateChildPartDesigns([NotNull] UIAssetBase asset, [NotNull] UIElementDesign elementDesign) { var assetPanel = (Panel)elementDesign.UIElement; foreach (var child in assetPanel.Children) { if (!asset.Hierarchy.Parts.TryGetValue(child.Id, out UIElementDesign childDesign)) { childDesign = new UIElementDesign(child); } if (child != childDesign.UIElement) { throw new InvalidOperationException(); } yield return(childDesign); } }
/// <summary> /// Creates a instance of the given control that can be added to another <see cref="UIAssetBase"/>. /// </summary> /// <param name="targetContainer">The container in which the instance will be added.</param> /// <param name="targetLocation">The location of this asset.</param> /// <param name="elementId">The id of the element to instantiate.</param> /// <param name="instanceId">The identifier of the created instance.</param> /// <returns>An <see cref="AssetCompositeHierarchyData{UIElementDesign, UIElement}"/> containing the cloned elements of </returns> /// <remarks>This method will update the <see cref="Asset.BaseParts"/> property of the <see paramref="targetContainer"/>.</remarks> public AssetCompositeHierarchyData<UIElementDesign, UIElement> CreateElementInstance(UIAssetBase targetContainer, string targetLocation, Guid elementId, out Guid instanceId) { // TODO: make a common base method in AssetCompositeHierarchy - the beginning of the method is similar to CreatePrefabInstance var idRemapping = new Dictionary<Guid, Guid>(); var instance = (UILibraryAsset)CreateDerivedAsset(targetLocation, idRemapping); var rootElementId = idRemapping[elementId]; if (!instance.Hierarchy.RootPartIds.Contains(rootElementId)) throw new ArgumentException(@"The given id cannot be found in the root parts of this library.", nameof(elementId)); instanceId = instance.Hierarchy.Parts.FirstOrDefault()?.Base.InstanceId ?? Guid.NewGuid(); var result = new AssetCompositeHierarchyData<UIElementDesign, UIElement>(); result.RootPartIds.Add(rootElementId); result.Parts.Add(instance.Hierarchy.Parts[rootElementId]); foreach (var element in EnumerateChildParts(instance.Hierarchy.Parts[rootElementId], instance.Hierarchy, true)) { result.Parts.Add(element); } return result; }
/// <summary> /// Creates a instance of the given control that can be added to another <see cref="UIAssetBase"/>. /// </summary> /// <param name="targetContainer">The container in which the instance will be added.</param> /// <param name="targetLocation">The location of the <see paramref="targetContainer"/> asset.</param> /// <param name="elementId">The id of the element to instantiate.</param> /// <returns>An <see cref="AssetCompositeHierarchyData{UIElementDesign, UIElement}"/> containing the cloned elements of </returns> /// <remarks>This method will update the <see cref="Asset.BaseParts"/> property of the <see paramref="targetContainer"/>.</remarks> public AssetCompositeHierarchyData<UIElementDesign, UIElement> CreateElementInstance(UIAssetBase targetContainer, string targetLocation, Guid elementId) { Guid unused; return CreateElementInstance(targetContainer, targetLocation, elementId, out unused); }