diff --git a/SharepointToolbox/Views/Converters/IndentConverter.cs b/SharepointToolbox/Views/Converters/IndentConverter.cs index 633dc1a..223d306 100644 --- a/SharepointToolbox/Views/Converters/IndentConverter.cs +++ b/SharepointToolbox/Views/Converters/IndentConverter.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Globalization; using System.Windows; using System.Windows.Data; @@ -46,3 +47,52 @@ public class InverseBoolConverter : IValueConverter => value is bool b && !b; } +/// +/// Converts a string to Visibility: Visible when non-empty, Collapsed when null or empty. +/// +[ValueConversion(typeof(string), typeof(Visibility))] +public class StringToVisibilityConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + => value is string s && !string.IsNullOrEmpty(s) ? Visibility.Visible : Visibility.Collapsed; + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + => throw new NotImplementedException(); +} + +/// +/// Converts an enum value to bool by comparing it with the ConverterParameter. +/// Used for RadioButton IsChecked bindings to enum properties. +/// +public class EnumBoolConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null || parameter == null) return false; + return value.ToString() == parameter.ToString(); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool b && b && parameter != null) + return Enum.Parse(targetType, parameter.ToString()!); + return System.Windows.DependencyProperty.UnsetValue; + } +} + +/// +/// Converts a List<string> to a single semicolon-separated string for display in DataGrid cells. +/// +public class ListToStringConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is IEnumerable list) + return string.Join("; ", list); + return string.Empty; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + => throw new NotImplementedException(); +} +