using System;
using System.Globalization;
using Avalonia;
using Avalonia.Data.Converters;
using Avalonia.Layout;
namespace Dock.Avalonia.Converters;
///
/// Converts model enum to avalonia enum.
///
public class OrientationConverter : IValueConverter
{
///
/// Gets instance.
///
public static readonly OrientationConverter Instance = new OrientationConverter();
///
/// Converts a value.
///
/// The value to convert.
/// The type of the target.
/// A user-defined parameter.
/// The culture to use.
/// The converted value.
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value switch
{
null => AvaloniaProperty.UnsetValue,
Model.Core.Orientation orientation => orientation switch
{
Model.Core.Orientation.Horizontal => Orientation.Horizontal,
Model.Core.Orientation.Vertical => Orientation.Vertical,
_ => throw new NotSupportedException($"Provided orientation is not supported in Avalonia.")
},
_ => value
};
}
///
/// Converts a value.
///
/// The value to convert.
/// The type of the target.
/// A user-defined parameter.
/// The culture to use.
/// The converted value.
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value switch
{
null => AvaloniaProperty.UnsetValue,
Orientation orientation => orientation switch
{
Orientation.Horizontal => Model.Core.Orientation.Horizontal,
Orientation.Vertical => Model.Core.Orientation.Vertical,
_ => throw new NotSupportedException($"Provided orientation is not supported in Model.")
},
_ => value
};
}
}