private ComponentElement CreateComponentElement() { if (!componentCache.ContainsKey(Model.Metadata.Element)) { ExportRendererAttribute rAttr = RendererManager.FromModelType(Model.Metadata.Element); var model = Activator.CreateInstance(rAttr.ModelType) as PComponent; var view = Activator.CreateInstance(rAttr.ViewType) as ComponentElement; view.SetIsFloating(true); view.SetComponentModel(model); view.HorizontalAlignment = HorizontalAlignment.Left; view.VerticalAlignment = VerticalAlignment.Top; view.Margin = new Thickness(10); componentCache[Model.Metadata.Element] = view; } var element = componentCache[Model.Metadata.Element]; if (element is Function functionElement) { var functionItemModel = Model as ToolBoxItemFunctionModel; functionElement.Model.SetRuntimeFunction(functionItemModel.MethodInfo); } return(element); }
/// <summary> /// 어셈블리의 <see cref="DesignElementAttribute"/> 특성으로 등록된 데이터 모델 <see cref="Type"/>의 <see cref="IRenderer{TModel, TElement}"/>를 생성 후 Parent의 자식으로 설정합니다. /// </summary> /// <param name="parent"></param> /// <param name="data"></param> /// <returns></returns> public FrameworkElement GenerateToElement( FrameworkElement parent, Type type, Point position = default(Point), bool pushTask = true) { var rendererAttr = RendererManager.FromModelType(type); var visual = RendererManager.CreateVisualRenderer(rendererAttr, position); if (visual == null) { return(null); } // * Task * if (pushTask) { IRenderer renderer = visual.GetRenderer(); // * Task * if (renderer is IRendererLayout lRenderer) { TaskManager?.Push( new LayoutTaskData( RendererTaskType.Add, lRenderer, () => AddElement(parent, visual, true), () => RemoveElement(parent, visual, true), () => DestroyElement(parent, visual))); } else if (renderer is IRendererElement eRenderer) { TaskManager?.Push( new ElementTaskData( RendererTaskType.Add, eRenderer, () => AddElement(parent, visual, true), () => RemoveElement(parent, visual, true), () => DestroyElement(parent, visual))); } } else { AddElement(parent, visual); } return(visual); }