mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 22:46:58 +00:00
Timer and TypeConverters to Shared
This commit is contained in:
parent
96557a9200
commit
8f01f63b99
7 changed files with 30 additions and 31 deletions
|
|
@ -13,6 +13,8 @@ using System.Windows;
|
|||
using Windows.UI.Xaml;
|
||||
#elif WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
#elif AVALONIA
|
||||
using Avalonia.Interactivity;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ using System.Windows.Media;
|
|||
using Windows.UI.Xaml.Media;
|
||||
#elif WINUI
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
#elif AVALONIA
|
||||
using ImageSource = Avalonia.Media.IImage;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
|
|
|
|||
36
MapControl/Shared/Timer.cs
Normal file
36
MapControl/Shared/Timer.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// Copyright © 2024 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
#if WPF
|
||||
using System.Windows.Threading;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml;
|
||||
#elif AVALONIA
|
||||
using Avalonia.Threading;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
internal static class Timer
|
||||
{
|
||||
public static DispatcherTimer CreateTimer(this object _, TimeSpan interval)
|
||||
{
|
||||
return new DispatcherTimer { Interval = interval };
|
||||
}
|
||||
|
||||
public static void Run(this DispatcherTimer timer, bool restart = false)
|
||||
{
|
||||
if (restart)
|
||||
{
|
||||
timer.Stop();
|
||||
}
|
||||
|
||||
if (!timer.IsEnabled)
|
||||
{
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
62
MapControl/Shared/TypeConverters.cs
Normal file
62
MapControl/Shared/TypeConverters.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// Copyright © 2024 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public class LocationConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
return sourceType == typeof(string);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
return Location.Parse((string)value);
|
||||
}
|
||||
}
|
||||
|
||||
public class LocationCollectionConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
return sourceType == typeof(string);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
return LocationCollection.Parse((string)value);
|
||||
}
|
||||
}
|
||||
|
||||
public class BoundingBoxConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
return sourceType == typeof(string);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
return BoundingBox.Parse((string)value);
|
||||
}
|
||||
}
|
||||
|
||||
public class TileSourceConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
return sourceType == typeof(string);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
return TileSource.Parse((string)value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue