Avalonia using declarations

This commit is contained in:
ClemensFischer 2024-05-27 11:05:22 +02:00
parent 3d275cd924
commit 286b158abe
41 changed files with 87 additions and 145 deletions

View file

@ -2,7 +2,6 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Avalonia.Controls;
using System;
#pragma warning disable AVP1001 // The same AvaloniaProperty should not be registered twice
@ -82,5 +81,10 @@ namespace MapControl
{
return AddOwner<TOwner, TValue>((StyledProperty<TValue>)property);
}
public static void SetBinding(this AvaloniaObject target, AvaloniaProperty property, Binding binding)
{
target.Bind(property, binding);
}
}
}

View file

@ -2,9 +2,6 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using System;
using System.IO;
using System.Threading.Tasks;

View file

@ -2,8 +2,6 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Avalonia.Animation;
namespace MapControl
{
public class LocationAnimator : InterpolatingAnimator<Location>

View file

@ -2,7 +2,6 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Avalonia.Input;
using System;
namespace MapControl

View file

@ -2,13 +2,6 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
global using Avalonia;
using Avalonia.Animation;
using Avalonia.Animation.Easings;
using Avalonia.Controls;
using Avalonia.Controls.Documents;
using Avalonia.Media;
using Avalonia.Styling;
using System.Threading;
using System.Threading.Tasks;

View file

@ -2,8 +2,6 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Avalonia.Controls;
namespace MapControl
{
/// <summary>

View file

@ -2,10 +2,6 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Avalonia.Controls;
using Avalonia.Controls.Documents;
using Avalonia.Controls.Shapes;
using Avalonia.Media;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

View file

@ -2,13 +2,24 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Avalonia.Controls;
using Avalonia.Media;
namespace MapControl
{
public partial class MapPanel
{
public static readonly AttachedProperty<bool> AutoCollapseProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, bool>("AutoCollapse");
public static readonly AttachedProperty<Location> LocationProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, Location>("Location");
public static readonly AttachedProperty<BoundingBox> BoundingBoxProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, BoundingBox>("BoundingBox");
static MapPanel()
{
AffectsParentArrange<MapPanel>(LocationProperty, BoundingBoxProperty);
}
public MapPanel()
{
if (this is MapBase mapBase)

View file

@ -2,9 +2,6 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Avalonia.Controls.Shapes;
using Avalonia.Media;
namespace MapControl
{
public partial class MapPath : Shape

View file

@ -2,7 +2,6 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Avalonia.Media;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;

View file

@ -4,10 +4,6 @@
using System.Threading.Tasks;
using System;
using Avalonia.Controls;
using Avalonia.Animation;
using Avalonia.Styling;
using System.Xml.Linq;
namespace MapControl
{

View file

@ -2,8 +2,6 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Avalonia.Controls;
using Avalonia.Media;
using System;
namespace MapControl

View file

@ -2,10 +2,7 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Avalonia.Media;
using Avalonia.Threading;
using System;
using System.IO;
using System.Threading.Tasks;
namespace MapControl
@ -16,7 +13,7 @@ namespace MapControl
/// Default folder where the Cache instance may save data, i.e. "C:\ProgramData\MapControl\TileCache".
/// </summary>
public static string DefaultCacheFolder =>
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "TileCache");
System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "TileCache");
private static async Task LoadTileAsync(Tile tile, Func<Task<IImage>> loadImageFunc)

View file

@ -13,8 +13,6 @@ using System.Windows;
using Windows.UI.Xaml;
#elif WINUI
using Microsoft.UI.Xaml;
#elif AVALONIA
using Avalonia.Interactivity;
#endif
namespace MapControl

View file

@ -11,8 +11,6 @@ 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

View file

@ -2,8 +2,6 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.IO;
namespace MapControl
{
public static class FilePath
@ -11,9 +9,9 @@ namespace MapControl
public static string GetFullPath(string path)
{
#if NET6_0_OR_GREATER
return Path.GetFullPath(path, System.AppDomain.CurrentDomain.BaseDirectory);
return System.IO.Path.GetFullPath(path, System.AppDomain.CurrentDomain.BaseDirectory);
#else
return Path.GetFullPath(path);
return System.IO.Path.GetFullPath(path);
#endif
}
}

View file

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using Path = System.IO.Path;
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
@ -23,12 +24,6 @@ using Windows.UI.Xaml.Media;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
#elif AVALONIA
using Avalonia.Controls;
using Avalonia.Media;
using DependencyProperty = Avalonia.AvaloniaProperty;
using FrameworkElement = Avalonia.Controls.Control;
using ImageSource = Avalonia.Media.IImage;
#endif
namespace MapControl

View file

@ -8,6 +8,7 @@ using Microsoft.Extensions.Options;
using System;
using System.Diagnostics;
using System.IO;
using Path = System.IO.Path;
using System.Linq;
using System.Text;
using System.Threading;

View file

@ -15,8 +15,6 @@ 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

View file

@ -2,7 +2,6 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
#if WPF
using System.Windows;
using System.Windows.Media;
@ -13,10 +12,33 @@ using Windows.UI.Xaml.Media;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
#elif AVALONIA
using Brush = Avalonia.Media.IBrush;
using DependencyProperty = Avalonia.AvaloniaProperty;
using UIElement = Avalonia.Controls.Control;
global using Avalonia;
global using Avalonia.Animation;
global using Avalonia.Animation.Easings;
global using Avalonia.Controls;
global using Avalonia.Controls.Documents;
global using Avalonia.Controls.Shapes;
global using Avalonia.Data;
global using Avalonia.Input;
global using Avalonia.Interactivity;
global using Avalonia.Media;
global using Avalonia.Media.Imaging;
global using Avalonia.Platform;
global using Avalonia.Styling;
global using Avalonia.Threading;
global using Brush = Avalonia.Media.IBrush;
global using ImageSource = Avalonia.Media.IImage;
global using DependencyObject = Avalonia.AvaloniaObject;
global using DependencyProperty = Avalonia.AvaloniaProperty;
global using UIElement = Avalonia.Controls.Control;
global using FrameworkElement = Avalonia.Controls.Control;
global using HorizontalAlignment = Avalonia.Layout.HorizontalAlignment;
global using VerticalAlignment = Avalonia.Layout.VerticalAlignment;
global using PathFigureCollection = Avalonia.Media.PathFigures;
global using PointCollection = System.Collections.Generic.List<Avalonia.Point>;
global using PropertyPath = System.String;
#endif
using System;
namespace MapControl
{

View file

@ -8,9 +8,6 @@ using System.Windows;
using Windows.UI.Xaml;
#elif WINUI
using Microsoft.UI.Xaml;
#elif AVALONIA
using DependencyProperty = Avalonia.AvaloniaProperty;
using FrameworkElement = Avalonia.Controls.Control;
#endif
namespace MapControl

View file

@ -15,10 +15,6 @@ using Windows.UI.Xaml.Media;
#elif WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
#elif AVALONIA
using Avalonia.Media;
using DependencyProperty = Avalonia.AvaloniaProperty;
using PathFigureCollection = Avalonia.Media.PathFigures;
#endif
namespace MapControl

View file

@ -20,13 +20,6 @@ using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using DispatcherTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
#elif AVALONIA
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Threading;
using Brush = Avalonia.Media.IBrush;
using DependencyProperty = Avalonia.AvaloniaProperty;
using ImageSource = Avalonia.Media.IImage;
#endif
namespace MapControl

View file

@ -18,13 +18,6 @@ using Windows.Foundation;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
#elif AVALONIA
using Avalonia.Controls;
using Avalonia.Media;
using DependencyProperty = Avalonia.AvaloniaProperty;
using FrameworkElement = Avalonia.Controls.Control;
using HorizontalAlignment = Avalonia.Layout.HorizontalAlignment;
using VerticalAlignment = Avalonia.Layout.VerticalAlignment;
#endif
/// <summary>
@ -43,17 +36,6 @@ namespace MapControl
public partial class MapPanel : Panel, IMapElement
{
public static readonly DependencyProperty AutoCollapseProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, bool>("AutoCollapse");
public static readonly DependencyProperty LocationProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, Location>("Location", null,
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
public static readonly DependencyProperty BoundingBoxProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, BoundingBox>("BoundingBox", null,
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
private static readonly DependencyProperty ViewPositionProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, Point?>("ViewPosition");

View file

@ -11,9 +11,6 @@ using Windows.UI.Xaml.Media;
#elif WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
#elif AVALONIA
using DependencyProperty = Avalonia.AvaloniaProperty;
using PathFigureCollection = Avalonia.Media.PathFigures;
#endif
namespace MapControl

View file

@ -9,8 +9,6 @@ using System.Windows;
using Windows.UI.Xaml;
#elif WINUI
using Microsoft.UI.Xaml;
#elif AVALONIA
using DependencyProperty = Avalonia.AvaloniaProperty;
#endif
namespace MapControl

View file

@ -9,8 +9,6 @@ using System.Windows;
using Windows.UI.Xaml;
#elif WINUI
using Microsoft.UI.Xaml;
#elif AVALONIA
using DependencyProperty = Avalonia.AvaloniaProperty;
#endif
namespace MapControl

View file

@ -24,14 +24,6 @@ using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Shapes;
#elif AVALONIA
using Avalonia.Data;
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using DependencyProperty = Avalonia.AvaloniaProperty;
using HorizontalAlignment = Avalonia.Layout.HorizontalAlignment;
using VerticalAlignment = Avalonia.Layout.VerticalAlignment;
using PointCollection = System.Collections.Generic.List<Avalonia.Point>;
#endif
namespace MapControl
@ -78,19 +70,12 @@ namespace MapControl
{
base.SetParentMap(map);
#if AVALONIA
line.Bind(Shape.StrokeProperty,
new Binding { Source = map, Path = nameof(MapBase.Foreground) });
line.Bind(Shape.StrokeThicknessProperty,
new Binding { Source = this, Path = nameof(StrokeThickness) });
#else
line.SetBinding(Shape.StrokeProperty,
new Binding { Source = map, Path = new PropertyPath(nameof(MapBase.Foreground)) });
line.SetBinding(Shape.StrokeThicknessProperty,
new Binding { Source = this, Path = new PropertyPath(nameof(StrokeThickness)) });
#endif
#if UWP || WINUI
label.SetBinding(TextBlock.ForegroundProperty,
new Binding { Source = map, Path = new PropertyPath(nameof(MapBase.Foreground)) });

View file

@ -15,9 +15,6 @@ using Windows.UI.Xaml.Media;
using Windows.Foundation;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
#elif AVALONIA
using Avalonia.Media;
using DependencyProperty = Avalonia.AvaloniaProperty;
#endif
namespace MapControl

View file

@ -19,12 +19,6 @@ using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using DispatcherTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
#elif AVALONIA
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Threading;
using Brush = Avalonia.Media.IBrush;
using DependencyProperty = Avalonia.AvaloniaProperty;
#endif
namespace MapControl

View file

@ -14,9 +14,6 @@ using Windows.UI.Xaml.Media;
using Windows.Foundation;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
#elif AVALONIA
using Avalonia.Media;
using HorizontalAlignment = Avalonia.Layout.HorizontalAlignment;
#endif
namespace MapControl

View file

@ -12,10 +12,6 @@ using Windows.UI.Xaml.Media;
#elif WINUI
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
#elif AVALONIA
using Avalonia.Controls;
using Avalonia.Media;
using ImageSource = Avalonia.Media.IImage;
#endif
namespace MapControl

View file

@ -9,7 +9,6 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@ -147,7 +146,7 @@ namespace MapControl
private static async Task LoadCachedTileAsync(Tile tile, Uri uri, string cacheName)
{
var extension = Path.GetExtension(uri.LocalPath);
var extension = System.IO.Path.GetExtension(uri.LocalPath);
if (string.IsNullOrEmpty(extension) || extension.Equals(".jpeg", StringComparison.OrdinalIgnoreCase))
{

View file

@ -10,8 +10,6 @@ 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

View file

@ -8,9 +8,6 @@ using System.Windows;
using System.Windows.Threading;
#elif UWP
using Windows.UI.Xaml;
#elif AVALONIA
using Avalonia.Threading;
using DependencyObject = Avalonia.AvaloniaObject;
#endif
namespace MapControl

View file

@ -17,9 +17,6 @@ using Windows.UI.Xaml.Media;
#elif WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
#elif AVALONIA
using DependencyProperty = Avalonia.AvaloniaProperty;
using ImageSource = Avalonia.Media.IImage;
#endif
namespace MapControl

View file

@ -15,9 +15,6 @@ using Windows.UI.Xaml;
#elif WINUI
using Windows.Foundation;
using Microsoft.UI.Xaml;
#elif AVALONIA
using Avalonia.Interactivity;
using DependencyProperty = Avalonia.AvaloniaProperty;
#endif
namespace MapControl

View file

@ -15,9 +15,6 @@ using Windows.UI.Xaml.Media;
using Windows.Foundation;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
#elif AVALONIA
using Avalonia.Controls;
using Avalonia.Media;
#endif
namespace MapControl

View file

@ -15,7 +15,9 @@ namespace MapControl
FrameworkPropertyMetadataOptions options)
where TOwner : DependencyObject
{
return DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), new FrameworkPropertyMetadata(defaultValue, options));
var metadata = new FrameworkPropertyMetadata(defaultValue, options);
return DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), metadata);
}
public static DependencyProperty Register<TOwner, TValue>(
@ -45,6 +47,16 @@ namespace MapControl
return DependencyProperty.Register(name, typeof(TValue), typeof(TOwner), metadata);
}
public static DependencyProperty RegisterAttached<TOwner, TValue>(
string name,
TValue defaultValue,
FrameworkPropertyMetadataOptions options)
{
var metadata = new FrameworkPropertyMetadata(defaultValue, options);
return DependencyProperty.RegisterAttached(name, typeof(TValue), typeof(TOwner), metadata);
}
public static DependencyProperty RegisterAttached<TOwner, TValue>(
string name,
TValue defaultValue = default,

View file

@ -11,6 +11,17 @@ namespace MapControl
{
public partial class MapPanel
{
public static readonly DependencyProperty AutoCollapseProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, bool>("AutoCollapse");
public static readonly DependencyProperty LocationProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, Location>("Location", null,
FrameworkPropertyMetadataOptions.AffectsParentArrange);
public static readonly DependencyProperty BoundingBoxProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, BoundingBox>("BoundingBox", null,
FrameworkPropertyMetadataOptions.AffectsParentArrange);
public MapPanel()
{
if (this is MapBase)

View file

@ -16,6 +16,17 @@ namespace MapControl
{
public partial class MapPanel
{
public static readonly DependencyProperty AutoCollapseProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, bool>("AutoCollapse");
public static readonly DependencyProperty LocationProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, Location>("Location", null,
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
public static readonly DependencyProperty BoundingBoxProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, BoundingBox>("BoundingBox", null,
(element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange());
public MapPanel()
{
InitMapElement(this);