using System; using System.Globalization; using System.Windows.Data; namespace HC_APTBS.Converters { /// /// Two-way converter that maps an enum value to/from its underlying value. /// /// Used to bind TabControl.SelectedIndex (int) to a ViewModel enum property. /// Convert and ConvertBack both honor the actual enum type — pass targetType as the /// enum type when converting back. /// public sealed class EnumToIntConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value is Enum ? System.Convert.ToInt32(value) : 0; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value is int i && targetType.IsEnum) return Enum.ToObject(targetType, i); return System.Windows.Data.Binding.DoNothing; } } }