28 lines
964 B
C#
28 lines
964 B
C#
using System;
|
|
using System.Globalization;
|
|
using Avalonia.Data.Converters;
|
|
using Avalonia.Media;
|
|
using XSDVisualiser.Models;
|
|
|
|
namespace XSDVisualiser.Desktop.Converters
|
|
{
|
|
public class OptionalToBorderBrushConverter : IValueConverter
|
|
{
|
|
private static readonly IBrush RequiredBrush = new SolidColorBrush(Color.FromRgb(0x33, 0x99, 0x33));
|
|
private static readonly IBrush OptionalBrush = new SolidColorBrush(Color.FromRgb(0xCC, 0x66, 0x33));
|
|
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is Occurs occ)
|
|
{
|
|
// Optional if minOccurs == 0
|
|
return occ.Min == 0 ? OptionalBrush : RequiredBrush;
|
|
}
|
|
return RequiredBrush;
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> throw new NotSupportedException();
|
|
}
|
|
}
|