Files
dashcaddy/desktop/ViewModels/Converters.cs
T
Hermes 86e4c9fc81 wip: Windows desktop app scaffold (WinUI 3/.NET 8) + NSIS installer + docs
Owner decision pending (STATE.md DC-100 tick): adopt/ship/park.
Preserved from fragile git stash to named branch 2026-08-23.
NOTE: requires a Windows build machine (WinUI XAML compiler + MSIX do not
cross-build on Linux) — see WINDOWS_APP_BUILD.md in this tree.
Secret-scanned clean 2026-08-23 (no keys/tokens/PEM in tree).
2026-08-22 23:50:34 -07:00

81 lines
2.5 KiB
C#

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI;
using DashCaddy.Desktop.ViewModels;
using Windows.UI;
namespace DashCaddy.Desktop.ViewModels;
public class StatusToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is ServiceHealth health)
{
return health switch
{
ServiceHealth.Healthy => new SolidColorBrush(Colors.LimeGreen),
ServiceHealth.Degraded => new SolidColorBrush(Colors.Gold),
ServiceHealth.Unhealthy => new SolidColorBrush(Colors.Red),
_ => new SolidColorBrush(Colors.Gray)
};
}
if (value is bool boolVal)
{
return boolVal ? new SolidColorBrush(Colors.LimeGreen) : new SolidColorBrush(Colors.Red);
}
return new SolidColorBrush(Colors.Gray);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
=> throw new NotImplementedException();
}
public class StatusToTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is ServiceHealth health)
{
return health switch
{
ServiceHealth.Healthy => "Healthy",
ServiceHealth.Degraded => "Degraded",
ServiceHealth.Unhealthy => "Unhealthy",
_ => "Unknown"
};
}
return "Unknown";
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
=> throw new NotImplementedException();
}
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is bool boolVal)
{
return boolVal ? Visibility.Visible : Visibility.Collapsed;
}
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
=> throw new NotImplementedException();
}
public class InverseBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is bool boolVal)
return !boolVal;
return true;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
=> throw new NotImplementedException();
}