ChronoFlow/ChronoFlow.View/Converter/BoolToBrushConverter.cs
2025-06-29 17:50:02 +02:00

51 lines
1.9 KiB
C#
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media;
namespace ChronoFlow.View.Converter
{
/// <summary>
/// Konvertiert einen booleschen Wert in eine Farbe (Brush).
/// True => Blau, False => Grau.
/// Wird z.B. für farbliche Statusanzeigen in der Oberfläche verwendet.
/// </summary>
public class BoolToBrushConverter : IValueConverter
{
/// <summary>
/// Die Farbe, die bei "true" verwendet wird.
/// Kann in XAML überschrieben werden.
/// </summary>
public IBrush TrueBrush { get; set; } = Brushes.Blue;
/// <summary>
/// Die Farbe, die bei "false" verwendet wird.
/// Kann in XAML überschrieben werden.
/// </summary>
public IBrush FalseBrush { get; set; } = Brushes.Gray;
/// <summary>
/// Führt die Umwandlung des bool-Wertes in eine Brush durch.
/// </summary>
/// <param name="value">Der Wert, der umgewandelt werden soll (sollte bool sein).</param>
/// <param name="targetType">Zieltyp der Bindung (erwartet IBrush).</param>
/// <param name="parameter">Optionaler Parameter (nicht verwendet).</param>
/// <param name="culture">Kultureinstellungen (nicht verwendet).</param>
/// <returns>TrueBrush oder FalseBrush abhängig vom bool-Wert.</returns>
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool boolValue && boolValue)
return TrueBrush;
return FalseBrush;
}
/// <summary>
/// Umkehrkonvertierung wird hier nicht benötigt.
/// </summary>
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException(); // wird i.d.R. nicht benötigt
}
}
}