/// <summary> /// Deserialize paint group /// </summary> /// <param name="jObject">paintgroup JObject</param> /// <param name="baseProps">basic shape properties</param> /// <returns>Paintgroup</returns> private PaintGroup GetPaintGroup(JObject jObject, PaintBaseProperties baseProps) { PaintGroup group = new PaintGroup { Height = baseProps.Height, Width = baseProps.Width, X = baseProps.X, Y = baseProps.Y }; if (jObject.GetValue("children") is JArray children) { // Deserialize children foreach (JToken child in children) { if (child is JObject jChild && Enum.TryParse(jChild.GetValue("type").ToString(), out PaintType type)) { PaintBaseProperties deserBase = GetBaseProperties(jChild); if (deserBase != null) { if (type == PaintType.Shape) { PaintShape shape = GetPaintShape(jChild, deserBase); if (shape != null) { group.Add(AddDecorators(jChild, shape)); } } else if (type == PaintType.Group) { // If child is a group, recursively deserialize to object PaintGroup innerGroup = GetPaintGroup(jChild, deserBase); if (innerGroup != null) { group.Add(AddDecorators(jChild, innerGroup)); } } } } } } return(group); }
public Task ExecuteUserActionAsync() { // Get selected items from ShapeList List <PaintBase> selected = ShapeList.Where(pb => pb.Selected).ToList(); // Only group if 2 or more items are selected if (selected.Count > 1) { // Add undo entry UndoStack.Push(ShapeList.DeepCopy()); RedoStack.Clear(); // Create new group PaintGroup newGroup = new PaintGroup() { Selected = true }; // Add selected items to the group // Remove selected items from the canvas itself foreach (PaintBase paintBase in selected) { ShapeList.Remove(paintBase); paintBase.Selected = false; newGroup.Add(paintBase); } ShapeList.Add(newGroup); _page.Draw(); _page.UpdateList(); } return(Task.CompletedTask); }