XAML-Map-Control/MapControl/Shared/TypeConverters.cs

135 lines
3.9 KiB
C#
Raw Normal View History

2025-02-27 18:46:32 +01:00
using System;
2017-08-04 21:38:58 +02:00
using System.ComponentModel;
using System.Globalization;
#if WPF
using System.Windows.Data;
#elif UWP
using Windows.UI.Xaml.Data;
#elif WINUI
using Microsoft.UI.Xaml.Data;
2025-08-19 19:43:02 +02:00
#elif AVALONIA
using Avalonia.Data.Converters;
#endif
#if UWP || WINUI
using ConverterCulture = System.String;
#else
using ConverterCulture = System.Globalization.CultureInfo;
#endif
2017-08-04 21:38:58 +02:00
2026-04-13 17:14:49 +02:00
namespace MapControl;
public partial class LocationConverter : TypeConverter, IValueConverter
2017-08-04 21:38:58 +02:00
{
2026-04-13 17:14:49 +02:00
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
2017-08-04 21:38:58 +02:00
{
2026-04-13 17:14:49 +02:00
return sourceType == typeof(string);
}
2017-08-04 21:38:58 +02:00
2026-04-13 17:14:49 +02:00
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return Location.Parse(value.ToString());
}
2026-04-13 17:14:49 +02:00
public object Convert(object value, Type targetType, object parameter, ConverterCulture culture)
{
return ConvertFrom(value.ToString());
}
2026-04-13 17:14:49 +02:00
public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture)
{
return value.ToString();
2017-08-04 21:38:58 +02:00
}
2026-04-13 17:14:49 +02:00
}
2017-08-04 21:38:58 +02:00
2026-04-13 17:14:49 +02:00
public partial class LocationCollectionConverter : TypeConverter, IValueConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
2017-08-04 21:38:58 +02:00
{
2026-04-13 17:14:49 +02:00
return sourceType == typeof(string);
}
2017-08-04 21:38:58 +02:00
2026-04-13 17:14:49 +02:00
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return LocationCollection.Parse(value.ToString());
}
2026-04-13 17:14:49 +02:00
public object Convert(object value, Type targetType, object parameter, ConverterCulture culture)
{
return ConvertFrom(value.ToString());
}
2026-04-13 17:14:49 +02:00
public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture)
{
return value.ToString();
2017-08-04 21:38:58 +02:00
}
2026-04-13 17:14:49 +02:00
}
2017-08-04 21:38:58 +02:00
2026-04-13 17:14:49 +02:00
public partial class BoundingBoxConverter : TypeConverter, IValueConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
2017-08-04 21:38:58 +02:00
{
2026-04-13 17:14:49 +02:00
return sourceType == typeof(string);
}
2017-08-04 21:38:58 +02:00
2026-04-13 17:14:49 +02:00
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return BoundingBox.Parse(value.ToString());
}
2026-04-13 17:14:49 +02:00
public object Convert(object value, Type targetType, object parameter, ConverterCulture culture)
{
return ConvertFrom(value.ToString());
}
2026-04-13 17:14:49 +02:00
public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture)
{
return value.ToString();
2017-08-04 21:38:58 +02:00
}
2026-04-13 17:14:49 +02:00
}
2017-08-04 21:38:58 +02:00
2026-04-13 17:14:49 +02:00
public partial class TileSourceConverter : TypeConverter, IValueConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
2017-08-04 21:38:58 +02:00
{
2026-04-13 17:14:49 +02:00
return sourceType == typeof(string);
}
2017-08-04 21:38:58 +02:00
2026-04-13 17:14:49 +02:00
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return TileSource.Parse(value.ToString());
}
2026-04-13 17:14:49 +02:00
public object Convert(object value, Type targetType, object parameter, ConverterCulture culture)
{
return ConvertFrom(value.ToString());
}
2025-09-06 13:06:00 +02:00
2026-04-13 17:14:49 +02:00
public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture)
{
return value.ToString();
2025-09-06 13:06:00 +02:00
}
2026-04-13 17:14:49 +02:00
}
2025-09-06 13:06:00 +02:00
2026-04-13 17:14:49 +02:00
public partial class MapProjectionConverter : TypeConverter, IValueConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
2025-09-06 13:06:00 +02:00
{
2026-04-13 17:14:49 +02:00
return sourceType == typeof(string);
}
2025-09-06 13:06:00 +02:00
2026-04-13 17:14:49 +02:00
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return MapProjection.Parse(value.ToString());
}
2025-09-06 13:06:00 +02:00
2026-04-13 17:14:49 +02:00
public object Convert(object value, Type targetType, object parameter, ConverterCulture culture)
{
return ConvertFrom(value.ToString());
}
2026-04-13 17:14:49 +02:00
public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture)
{
return value.ToString();
2017-08-04 21:38:58 +02:00
}
}