private void AddItemControl(ActionItemModel action, IActionBuilder builder = null) { isRendering = true; double Y = 0; if (ActionItems.Count > 0) { var lastItem = ActionItems.Last(); var lastItemTTF = lastItem.RenderTransform as TranslateTransform; Y = lastItemTTF.Y + lastItem.ActualHeight; } var item = new ActionItem(); item.ActionContainer = this; item.DataContext = this; item.VMDataContext = this.DataContext; BindingOperations.SetBinding(item, ActionItem.ContainerStateProperty, new Binding() { Source = this, Path = new PropertyPath(nameof(State)), Mode = BindingMode.Default, }); BindingOperations.SetBinding(item, ActionItem.RuningIDProperty, new Binding() { Source = DataContext, Path = new PropertyPath("RuningActionID"), Mode = BindingMode.Default, }); BindingOperations.SetBinding(item, ActionItem.RuningStateProperty, new Binding() { Source = DataContext, Path = new PropertyPath("RuningActionState"), Mode = BindingMode.Default, }); item.ID = action.ID; //item.InputDataModel = inputdata == null ? ActionData.GetCreateDefaultInputData(action.ActionType) : inputdata; item.Builder = builder == null?ActionBuilder.BuilderByActionItem(action) : builder; item.Action = action; item.VerticalAlignment = VerticalAlignment.Top; var ttf = item.RenderTransform as TranslateTransform; ttf.Y = Y; item.Y = Y; item.MouseLeftButtonDown += Item_MouseLeftButtonDown; item.MouseLeftButtonUp += Item_MouseLeftButtonUp; item.MouseMove += Item_MouseMove; ttf.Changed += (e, c) => { item.Y = ttf.Y; }; item.OnRenderDone += (e, c) => { if (item.Tag != null) { //如果tag不为null表示已加载完成了 return; } item.Tag = string.Empty; if (ActionItems.Count == 1) { //仅存在一个时使用auto height ActionPanel.Height = Double.NaN; } else { ActionPanel.Height = ActionPanel.ActualHeight + item.ActualHeight; } //ActionPanel.Height += item.ActualHeight; //if (double.IsNaN(ActionPanel.Height)) //{ // ActionPanel.Height = item.ActualHeight; //} UpdateActionHeight(item); ActionTempPanel.Children.Remove(item); ActionPanel.Children.Add(item); //继续队列 appendActionItemTempList.RemoveAt(0); appendBuilderTempList.RemoveAt(0); isRendering = false; if (appendActionItemTempList.Count > 0) { AddItem(appendActionItemTempList[0], appendBuilderTempList[0]); } else { ResetAllActionsMarigin(); } //继续监控item高度变化 item.LayoutUpdated += (e, v) => { UpdateActionHeight(item); }; }; //ActionPanel.Children.Add(item); //添加到临时容器中 ActionTempPanel.Children.Add(item); ActionItems.Add(item); SortAction(); }