mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Combine TypeConverters and IValueConverters
This commit is contained in:
parent
12d13465e9
commit
4b60e7dde5
|
|
@ -4,6 +4,7 @@ global using Avalonia.Animation.Easings;
|
||||||
global using Avalonia.Controls;
|
global using Avalonia.Controls;
|
||||||
global using Avalonia.Controls.Documents;
|
global using Avalonia.Controls.Documents;
|
||||||
global using Avalonia.Data;
|
global using Avalonia.Data;
|
||||||
|
global using Avalonia.Data.Converters;
|
||||||
global using Avalonia.Input;
|
global using Avalonia.Input;
|
||||||
global using Avalonia.Interactivity;
|
global using Avalonia.Interactivity;
|
||||||
global using Avalonia.Media;
|
global using Avalonia.Media;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,22 @@
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Globalization;
|
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
|
namespace MapControl
|
||||||
{
|
{
|
||||||
public class LocationConverter : TypeConverter
|
public class LocationConverter : TypeConverter, IValueConverter
|
||||||
{
|
{
|
||||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||||
{
|
{
|
||||||
|
|
@ -13,11 +25,21 @@ namespace MapControl
|
||||||
|
|
||||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
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)
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||||
{
|
{
|
||||||
|
|
@ -26,11 +48,21 @@ namespace MapControl
|
||||||
|
|
||||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
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)
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||||
{
|
{
|
||||||
|
|
@ -39,11 +71,21 @@ namespace MapControl
|
||||||
|
|
||||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
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)
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||||
{
|
{
|
||||||
|
|
@ -52,7 +94,17 @@ namespace MapControl
|
||||||
|
|
||||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -188,6 +188,9 @@
|
||||||
<Compile Include="..\Shared\TransverseMercatorProjection.cs">
|
<Compile Include="..\Shared\TransverseMercatorProjection.cs">
|
||||||
<Link>TransverseMercatorProjection.cs</Link>
|
<Link>TransverseMercatorProjection.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="..\Shared\TypeConverters.cs">
|
||||||
|
<Link>TypeConverters.cs</Link>
|
||||||
|
</Compile>
|
||||||
<Compile Include="..\Shared\ViewportChangedEventArgs.cs">
|
<Compile Include="..\Shared\ViewportChangedEventArgs.cs">
|
||||||
<Link>ViewportChangedEventArgs.cs</Link>
|
<Link>ViewportChangedEventArgs.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
@ -278,9 +281,6 @@
|
||||||
<Compile Include="..\WinUI\Tile.WinUI.cs">
|
<Compile Include="..\WinUI\Tile.WinUI.cs">
|
||||||
<Link>Tile.WinUI.cs</Link>
|
<Link>Tile.WinUI.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="..\WinUI\ValueConverters.cs">
|
|
||||||
<Link>ValueConverters.cs</Link>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="TileImageLoader.UWP.cs" />
|
<Compile Include="TileImageLoader.UWP.cs" />
|
||||||
<EmbeddedResource Include="Properties\MapControl.UWP.rd.xml" />
|
<EmbeddedResource Include="Properties\MapControl.UWP.rd.xml" />
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="..\Shared\TypeConverters.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<!-- Directly referencing "Microsoft.Web.WebView2 is a workaround for a bug in WindowsAppSDK, https://github.com/microsoft/WindowsAppSDK/issues/4807 -->
|
|
||||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.7.250606001" />
|
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.7.250606001" />
|
||||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.4948" />
|
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.4948" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.8" />
|
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.8" />
|
||||||
|
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
using System;
|
|
||||||
#if UWP
|
|
||||||
using Windows.UI.Xaml.Data;
|
|
||||||
#elif WINUI
|
|
||||||
using Microsoft.UI.Xaml.Data;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace MapControl
|
|
||||||
{
|
|
||||||
public class LocationConverter : IValueConverter
|
|
||||||
{
|
|
||||||
public object Convert(object value, Type targetType, object parameter, string language)
|
|
||||||
{
|
|
||||||
return Location.Parse(value.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
|
||||||
{
|
|
||||||
return value.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LocationCollectionConverter : IValueConverter
|
|
||||||
{
|
|
||||||
public object Convert(object value, Type targetType, object parameter, string language)
|
|
||||||
{
|
|
||||||
return LocationCollection.Parse(value.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
|
||||||
{
|
|
||||||
return value.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class BoundingBoxConverter : IValueConverter
|
|
||||||
{
|
|
||||||
public object Convert(object value, Type targetType, object parameter, string language)
|
|
||||||
{
|
|
||||||
return BoundingBox.Parse(value.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
|
||||||
{
|
|
||||||
return value.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TileSourceConverter : IValueConverter
|
|
||||||
{
|
|
||||||
public object Convert(object value, Type targetType, object parameter, string language)
|
|
||||||
{
|
|
||||||
return TileSource.Parse(value.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
|
||||||
{
|
|
||||||
return value.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue