using System.Globalization; using Avalonia.Data.Converters; namespace JdeScoping.SecureStoreManager.Converters; /// /// Inverts a boolean value. /// public class InverseBooleanConverter : IValueConverter { /// /// Converts a boolean value to its inverted counterpart. /// /// The boolean value to invert. /// The target type (ignored). /// An optional parameter (ignored). /// The culture information (ignored). /// The inverted boolean value, or false if the input is not a boolean. public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is bool boolValue) { return !boolValue; } return false; } /// /// Converts a value back to a boolean by inverting it. /// /// The value to invert. /// The target type (ignored). /// An optional parameter (ignored). /// The culture information (ignored). /// The inverted boolean value, or false if the input is not a boolean. public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is bool boolValue) { return !boolValue; } return false; } } /// /// Converts a boolean to a visibility icon (eye open/closed). /// public class BooleanToVisibilityIconConverter : IValueConverter { /// /// Converts a boolean to a visibility icon string. /// /// The boolean value indicating visibility. /// The target type (ignored). /// An optional parameter (ignored). /// The culture information (ignored). /// "Hide" if true, "Show" if false or input is not boolean. public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is bool isVisible) { // Use simple text icons for cross-platform compatibility return isVisible ? "Hide" : "Show"; } return "Show"; } /// /// Converts a value back (not implemented for visibility icons). /// /// The value to convert back (ignored). /// The target type (ignored). /// An optional parameter (ignored). /// The culture information (ignored). /// Not implemented. /// Always thrown. public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { throw new NotImplementedException(); } } /// /// Converts null to bool (null = false, not null = true). /// public class NullToBoolConverter : IValueConverter { /// /// Converts a value to a boolean based on null status. /// /// The value to check for null. /// The target type (ignored). /// An optional parameter (ignored). /// The culture information (ignored). /// True if value is not null, false otherwise. public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { return value != null; } /// /// Converts a value back (not implemented for null checks). /// /// The value to convert back (ignored). /// The target type (ignored). /// An optional parameter (ignored). /// The culture information (ignored). /// Not implemented. /// Always thrown. public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { throw new NotImplementedException(); } } /// /// Converts a string to bool (empty = false, not empty = true). /// public class StringToBoolConverter : IValueConverter { /// /// Converts a string to a boolean based on whether it's empty or null. /// /// The string value to check. /// The target type (ignored). /// An optional parameter (ignored). /// The culture information (ignored). /// True if string is not null or whitespace, false otherwise. public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is string str) { return !string.IsNullOrWhiteSpace(str); } return false; } /// /// Converts a value back (not implemented for string checks). /// /// The value to convert back (ignored). /// The target type (ignored). /// An optional parameter (ignored). /// The culture information (ignored). /// Not implemented. /// Always thrown. public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { throw new NotImplementedException(); } }