var selectedElements = graphicsLayer.GetSelectedElements().ToList(); ;
if (selectedElements?.Any() == false)//must be at least 1.
return;
var elementsToUnGroup = new List<GroupElement>();
//All selected elements should be grouped.
if (selectedElements.Count() == selectedElements.OfType<GroupElement>().Count())
{
//Convert to a GroupElement list.
elementsToUnGroup = selectedElements.ConvertAll(x => (GroupElement)x);
}
if (elementsToUnGroup.Count() == 0)
return;
//UnGroup
graphicsLayer.UnGroupElements(elementsToUnGroup);