private void RenderActions() { string category = null; var margin = new Thickness(16, 0, 0, 0); foreach (var item in ActionItems.OrderBy(c => c.Category).ThenBy(c => c.Text)) { if (item.Category != category) { category = item.Category; var c = new ListBoxItem { Content = category, IsEnabled = false, FontWeight = FontWeights.Bold, BorderThickness = new Thickness(0, 0, 0, 1), BorderBrush = SystemColors.ControlDarkBrush, Foreground = SystemColors.WindowTextBrush, Margin = new Thickness(4, 8, 4, 0) }; Actions.Items.Add(c); } var listBoxItem = new ListBoxItem { Content = RenderText(item.Text.Trim()), Tag = item, Margin = margin }; Actions.Items.Add(listBoxItem); } }
/// <summary> /// 根据action位置排序分配index /// </summary> private void SortAction() { ActionItems = ActionItems.OrderBy(m => m.Y).ToList(); for (int i = 0; i < ActionItems.Count; i++) { //var item = Items.Where(m => m.ID == actionItems[i].ID).FirstOrDefault(); //if (item != null) //{ // item.Index = i; //} ActionItems[i].Action.Index = i; } ItemIndexChanged?.Invoke(this, null); }
private void UpdateActionsLocation() { var actions = ActionItems.OrderBy(m => m.Y).ToList(); for (int i = 0; i < actions.Count; i++) { var actionPoint = actions[i].RenderTransform as TranslateTransform; if (i == 0) { actionPoint.Y = 0; actions[i].Y = 0; } else { var topAction = actions[i - 1]; actionPoint.Y = topAction.Y + topAction.ActualHeight; actions[i].Y = actionPoint.Y; } } }