mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 14:37:01 +00:00
Combine TypeConverters and IValueConverters
This commit is contained in:
parent
12d13465e9
commit
4b60e7dde5
5 changed files with 64 additions and 77 deletions
|
|
@ -1,10 +1,22 @@
|
|||
using System;
|
||||
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;
|
||||
#endif
|
||||
#if UWP || WINUI
|
||||
using ConverterCulture = System.String;
|
||||
#else
|
||||
using ConverterCulture = System.Globalization.CultureInfo;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public class LocationConverter : TypeConverter
|
||||
public class LocationConverter : TypeConverter, IValueConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
|
|
@ -13,11 +25,21 @@ namespace MapControl
|
|||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
return Location.Parse((string)value);
|
||||
return Location.Parse(value.ToString());
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, ConverterCulture culture)
|
||||
{
|
||||
return Location.Parse(value.ToString());
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture)
|
||||
{
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public class LocationCollectionConverter : TypeConverter
|
||||
public class LocationCollectionConverter : TypeConverter, IValueConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
|
|
@ -26,11 +48,21 @@ namespace MapControl
|
|||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
return LocationCollection.Parse((string)value);
|
||||
return LocationCollection.Parse(value.ToString());
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, ConverterCulture culture)
|
||||
{
|
||||
return LocationCollection.Parse(value.ToString());
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture)
|
||||
{
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public class BoundingBoxConverter : TypeConverter
|
||||
public class BoundingBoxConverter : TypeConverter, IValueConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
|
|
@ -39,11 +71,21 @@ namespace MapControl
|
|||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
return BoundingBox.Parse((string)value);
|
||||
return BoundingBox.Parse(value.ToString());
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, ConverterCulture culture)
|
||||
{
|
||||
return BoundingBox.Parse(value.ToString());
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture)
|
||||
{
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public class TileSourceConverter : TypeConverter
|
||||
public class TileSourceConverter : TypeConverter, IValueConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
|
|
@ -52,7 +94,17 @@ namespace MapControl
|
|||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
return TileSource.Parse((string)value);
|
||||
return TileSource.Parse(value.ToString());
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, ConverterCulture culture)
|
||||
{
|
||||
return TileSource.Parse(value.ToString());
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, ConverterCulture culture)
|
||||
{
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue