38 lines
934 B
C#
38 lines
934 B
C#
using Microsoft.UI.Xaml;
|
|
using Microsoft.UI.Xaml.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace Harmonia.WinUI.Converters;
|
|
|
|
public class BooleanToVisibilityConverter : IValueConverter
|
|
{
|
|
public Visibility TrueValue { get; set; }
|
|
public Visibility FalseValue { get; set; }
|
|
|
|
public BooleanToVisibilityConverter()
|
|
{
|
|
TrueValue = Visibility.Visible;
|
|
FalseValue = Visibility.Collapsed;
|
|
}
|
|
|
|
public object? Convert(object value, Type targetType, object parameter, string language)
|
|
{
|
|
if (!(value is bool))
|
|
return null;
|
|
|
|
return (bool)value ? TrueValue : FalseValue;
|
|
}
|
|
|
|
public object? ConvertBack(object value, Type targetType, object parameter, string language)
|
|
{
|
|
if (Equals(value, TrueValue))
|
|
return true;
|
|
|
|
if (Equals(value, FalseValue))
|
|
return false;
|
|
|
|
return null;
|
|
}
|
|
} |