Files
WinWARP/WinWARP.Ui/Converters/BoolToVisibilityConverter.cs
T
2026-09-09 16:19:45 +03:00

47 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Markup;
namespace WinWARP.Ui.Converters;
[MarkupExtensionReturnType(ReturnType = typeof(IValueConverter))]
public partial class BoolToVisibilityConverter : MarkupExtension, IValueConverter
{
public bool IsInverted { get; set; } = false;
// IValueConverter implementation
public object Convert(object value, Type targetType, object parameter, string language)
{
bool flag = false;
if (value is bool boolValue)
{
flag = boolValue;
}
if (IsInverted)
{
flag = !flag;
}
return flag ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
if (value is Visibility visibility)
{
bool result = (visibility == Visibility.Visible);
return IsInverted ? !result : result;
}
return false;
}
// MarkupExtension override returning self as the instance
protected override object ProvideValue()
{
return this;
}
}