public static void Group(BaseElement element, Guid id, List <BaseViewModelComponent> elements) { foreach (var pin in element.GetAllPins()) { foreach (var coPin in pin.CoWorker) { var targetElement = elements.Find(x => x.GetElementModel().Id == coPin.ParentId).GetElementModel(); if (targetElement.GroupID == default || element.GroupID != targetElement.GroupID) { targetElement.GroupID = id; Group(targetElement, targetElement.GroupID, elements); } } } }