GeoImage and DependencyPropertyHelper implementation

This commit is contained in:
ClemensFischer 2024-09-13 22:21:38 +02:00
parent 0344db4b9b
commit 1b0e73dc35
12 changed files with 190 additions and 154 deletions

View file

@ -10,6 +10,23 @@ namespace MapControl
{
public static class DependencyPropertyHelper
{
public static AttachedProperty<TValue> RegisterAttached<TValue>(
string name,
Type ownerType,
TValue defaultValue = default,
Action<Control, TValue, TValue> changed = null,
bool inherits = false)
{
var property = AvaloniaProperty.RegisterAttached<Control, TValue>(name, ownerType, defaultValue, inherits);
if (changed != null)
{
property.Changed.AddClassHandler<Control, TValue>((o, e) => changed(o, e.OldValue.Value, e.NewValue.Value));
}
return property;
}
public static StyledProperty<TValue> Register<TOwner, TValue>(
string name,
TValue defaultValue = default,
@ -38,22 +55,6 @@ namespace MapControl
return property;
}
public static AttachedProperty<TValue> RegisterAttached<TOwner, TValue>(
string name,
TValue defaultValue = default,
Action<Control, TValue, TValue> changed = null,
bool inherits = false)
{
var property = AvaloniaProperty.RegisterAttached<TOwner, Control, TValue>(name, defaultValue, inherits);
if (changed != null)
{
property.Changed.AddClassHandler<Control, TValue>((o, e) => changed(o, e.OldValue.Value, e.NewValue.Value));
}
return property;
}
public static StyledProperty<TValue> AddOwner<TOwner, TValue>(
StyledProperty<TValue> property,
TValue defaultValue = default,

View file

@ -7,13 +7,16 @@ using System.Threading.Tasks;
namespace MapControl
{
public partial class GeoImage
public static partial class GeoImage
{
private Point BitmapSize => new(bitmapSource.PixelSize.Width, bitmapSource.PixelSize.Height);
private partial class GeoBitmap
{
public Point BitmapSize => new(BitmapSource.PixelSize.Width, BitmapSource.PixelSize.Height);
private ImageBrush ImageBrush => new(bitmapSource);
public ImageBrush ImageBrush => new(BitmapSource);
}
private Task LoadGeoTiffAsync(string sourcePath)
private static Task<GeoBitmap> LoadGeoTiffAsync(string sourcePath)
{
throw new InvalidOperationException("GeoTIFF is not supported.");
}

View file

@ -9,13 +9,13 @@ namespace MapControl
public partial class MapPanel
{
public static readonly AttachedProperty<bool> AutoCollapseProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, bool>("AutoCollapse");
DependencyPropertyHelper.RegisterAttached<bool>("AutoCollapse", typeof(MapPanel));
public static readonly AttachedProperty<Location> LocationProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, Location>("Location");
DependencyPropertyHelper.RegisterAttached<Location>("Location", typeof(MapPanel));
public static readonly AttachedProperty<BoundingBox> BoundingBoxProperty =
DependencyPropertyHelper.RegisterAttached<MapPanel, BoundingBox>("BoundingBox");
DependencyPropertyHelper.RegisterAttached<BoundingBox>("BoundingBox", typeof(MapPanel));
protected IEnumerable<Control> ChildElements => Children;