private void AddItemIntoCanvas(BlockControl block) { var container = new DesignerItemContainer(); container.Content = block; block.Container = container; SetComponent(container, block); //应用样式 var containerStyle = this.BlockContainerStyle; if (containerStyle != null) { container.Style = containerStyle; } container.DataContext = block; container.SetBinding(Canvas.LeftProperty, new Binding { Path = new PropertyPath(BlockControl.LeftProperty), Mode = BindingMode.TwoWay }); container.SetBinding(Canvas.TopProperty, new Binding { Path = new PropertyPath(BlockControl.TopProperty), Mode = BindingMode.TwoWay }); _canvas.Children.Add(container); }
private void RemoveItemFromCanvas(BlockControl block) { //先把所有的连接都移除。 foreach (var con in block.Container.Connections) { var connection = GetComponent(con) as BlockRelation; this.Relations.Remove(connection); } _canvas.Children.Remove(block.Container); }
private void _canvas_DragLineCompleted(object sender, CanvasDragLineCompletedEventArgs e) { var source = BlockControl.GetBlockControl(e.Source); var sink = BlockControl.GetBlockControl(e.Sink); var relation = new BlockRelation { FromBlock = source.TypeFullName, ToBlock = sink.TypeFullName }; this.Relations.Insert(0, relation); this.OnRelationAdded(relation); }
/// <summary> /// 绑定 From、To /// </summary> /// <param name="from"></param> /// <param name="to"></param> private void BindBlocks() { ResetSource(); ResetSink(); _connection.SourceChanged += (o, e) => { var sourceBlock = BlockControl.GetBlockControl(_connection.Source); this.FromBlock = sourceBlock.TypeFullName; }; _connection.SinkChanged += (o, e) => { var sinkBlock = BlockControl.GetBlockControl(_connection.Sink); this.ToBlock = sinkBlock.TypeFullName; }; }