private void CoerceSelectedItem(ISpritePartGroupPart groupPart, [CallerMemberName] string callerName = null) { if (supressEvents) { return; } string propName = "null"; if (GetBindingExpression(ItemsSourceProperty) != null) { propName = GetBindingExpression(ItemsSourceProperty).ResolvedSourcePropertyName; } Console.WriteLine($"{propName} SpritePartGroupComboBox.{callerName} coerce"); supressEvents = true; ISpritePartGroup source = ItemsSource; if (source == null) { groupPart = null; } else if (groupPart != null && source.TryGetValue(groupPart.Id, out ISpritePartGroupPart newGroupPart)) { groupPart = newGroupPart; } else if (source.IsEnabledByDefault && source.GroupParts.Count > 1) { groupPart = source.GroupParts[1]; } else { groupPart = source.GroupParts[0]; } SelectedItem = groupPart; SelectedItemInternal = groupPart; supressEvents = false; }
bool ISpritePartGroup.TryGetValue(int id, out ISpritePartGroupPart value) { value = GroupParts.Find(gp => gp.Id == id); return(value != null); }