using System; using System.Globalization; using Avalonia; using Avalonia.Data.Converters; using Dock.Model.Core; using AC = Avalonia.Controls; namespace Dock.Avalonia.Converters; /// /// Converts model enum to avalonia enum. /// public class DockModeConverter : IValueConverter { /// /// Gets instance. /// public static readonly DockModeConverter Instance = new DockModeConverter(); /// /// 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, DockMode dock => dock switch { DockMode.Left => AC.Dock.Left, DockMode.Bottom => AC.Dock.Bottom, DockMode.Right => AC.Dock.Right, DockMode.Top => AC.Dock.Top, _ => AvaloniaProperty.UnsetValue }, _ => 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, AC.Dock dock => dock switch { AC.Dock.Left => DockMode.Left, AC.Dock.Bottom => DockMode.Bottom, AC.Dock.Right => DockMode.Right, AC.Dock.Top => DockMode.Top, _ => DockMode.Center }, _ => value }; } }