public SketchItemDisplay(SketchPad parent, ISketchItemContainer container, bool activateCanvas = true) { this.Height = parent.Height; this.Width = parent.Width; _parent = parent; _container = container; Focusable = true; Background = Brushes.White; var items = new List <ISketchItemModel>(_container.SketchItems); foreach (var item in items) { AddVisualChild(item); } _container.SketchItems.CollectionChanged += SketchItems_CollectionChanged; if (activateCanvas) { Visibility = Visibility.Visible; _myLabel = new SketchItemDisplayLabel(container, this); BeginEdit(new SelectUisOperation(this)); } }
public OutlineUI(SketchPad pad, ISketchItemDisplay parent, object modelInstance) : base() { if (modelInstance is ConnectableBase model) { _sketchPad = pad; _model = model; _model.Decorators.CollectionChanged += Decorators_CollectionChanged; Content = model; IsHitTestVisible = true; Canvas.SetLeft(this, model.Bounds.Left); Canvas.SetTop(this, model.Bounds.Top); _parent = parent; var tools = model.AllowableConnectors; if (tools.Count > 0) { InitTools(tools); } this.DataContext = model; this.SetBinding(LabelProperty, model.LabelPropertyName); var boundsBinding = new Binding(nameof(Bounds)) { Mode = BindingMode.OneWay }; this.SetBinding(BoundsProperty, boundsBinding); this.SetBinding(GeometryProperty, nameof(Geometry)); this.Visibility = System.Windows.Visibility.Visible; // some of the bindings must only occur after the shadow was created! _adorner = new OutlineAdorner(this, parent); _decoratorAdorner = new DecoratorAdorner(this, parent); var isSelecteBinding = new Binding("IsSelected") { Mode = BindingMode.TwoWay }; this.SetBinding(IsSelectedProperty, isSelecteBinding); var isMarkedBinding = new Binding("IsMarked") { Mode = BindingMode.TwoWay }; this.SetBinding(IsMarkedProperty, isMarkedBinding); this.SetBinding(CanChangeSizeProperty, nameof(CanChangeSize)); InitContextMenu(model); } else { throw new NotSupportedException("The model needs to be derived from ConnectableBase"); } }