using System; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Data; namespace Marechai.App.Presentation.Converters; /// /// Converts null object to Collapsed visibility /// public class ObjectToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) => value != null ? Visibility.Visible : Visibility.Collapsed; public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException(); } /// /// Converts empty/null string to Collapsed visibility /// public class StringToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { if(value is string str && !string.IsNullOrWhiteSpace(str)) return Visibility.Visible; return Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException(); } /// /// Converts zero count to Collapsed visibility, otherwise Visible /// public class ZeroToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { if(value is int count && count > 0) return Visibility.Visible; if(value is long longCount && longCount > 0) return Visibility.Visible; return Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException(); }