public void AddElement(FrameworkElement parent, FrameworkElement element, bool pushTask = false) { IRenderer parentRenderer = parent.GetRenderer(); IRenderer childRenderer = element.GetRenderer(); element.AddAdorner((Adorner)childRenderer); if (parent.DataContext != null && parent.DataContext is DependencyObject dataContext) { // Add On PObject Parent ObjectContentHelper.GetContent( dataContext, pi => pi.SetValue(dataContext, element.DataContext), // Single Content list => list.SafeAdd(element.DataContext)); // List Content } // Add On WPF Parent ObjectContentHelper.GetContent( parent, pi => pi.SetValue(parent, element), // Single Content list => list.SafeAdd(element)); // List Content this.AddElementCore(childRenderer); // Notice child added parentRenderer?.AddChild(childRenderer, childRenderer.Metadata.CreatedPosition); }
protected override void OnDisposed() { ObjectContentHelper.GetContent( AdornedElement, null, list => { foreach (FrameworkElement element in list) { IRenderer renderer = element.GetRenderer(); if (renderer is IDisposable disposable) { disposable.Dispose(); } } }); base.OnDisposed(); }
/// <summary> /// Parent의 자식으로 등록된 Element를 삭제하고 <see cref="IRenderer"/> 및 레이어를 삭제합니다. /// </summary> /// <param name="parent"></param> /// <param name="element"></param> public void RemoveElement(FrameworkElement parent, FrameworkElement element, bool pushTask = false) { IRenderer parentRenderer = parent.GetRenderer(); IRenderer childRenderer = element.GetRenderer(); // Selection Check if (GroupSelector.IsSelected(childRenderer as FrameworkElement)) { GroupSelector.Select(childRenderer as SelectionLayer, false); } // Remove On AdornerLayer element.RemoveAdorner((Adorner)childRenderer); if (!pushTask) { // Dispose DestroyElement(parent, element); } if (parent.DataContext != null && parent.DataContext is DependencyObject dataContext) { // Remove On PObject Parent ObjectContentHelper.GetContent( dataContext, pi => pi.SetValue(dataContext, null), // Single Content list => list.SafeRemove(element.DataContext)); // List Content } // Remove On WPF Parent ObjectContentHelper.GetContent( parent, pi => pi.SetValue(parent, null), // Single Content list => list.SafeRemove(element)); // List Content RemoveElementCore(childRenderer); // Notice child removed parentRenderer?.RemoveChild(childRenderer); }