Пример #1
0
        private static FrameworkElement CreateVisualRendererCore(ExportRendererAttribute rendererAttr, PObject model, Point position)
        {
            var view     = (FrameworkElement)Activator.CreateInstance(rendererAttr.ViewType);
            var renderer = (IRenderer)Activator.CreateInstance(rendererAttr.RendererType, view, model);

            if (model.Guid.Equals(Guid.Empty))
            {
                model.Guid = Guid.NewGuid();
            }

            GlobalModels.Register(model.Guid, model);

            // metadata setting
            renderer.Metadata.CreatedTime     = DateTime.Now;
            renderer.Metadata.CreatedPosition = position;

            view.DataContext = model;
            view.AddAdorner((Adorner)renderer, zindex: 1);

            // View <-> Model
            view.SetModel(model);
            model.SetView(view);

            // View, Model -> Renderer
            view.SetRenderer(renderer);
            model.SetRenderer(renderer);

            // BinderHost -> Renderer
            (renderer.GetBinderHost() as PBinderHost).SetRenderer(renderer);

            return(view);
        }