|
@@ -8,9 +8,14 @@ using Avalonia.Layout;
|
|
|
using Avalonia.Markup.Xaml;
|
|
|
using Avalonia.Media;
|
|
|
using Avalonia.Metadata;
|
|
|
+using System;
|
|
|
|
|
|
namespace InABox.Avalonia.Components;
|
|
|
|
|
|
+/// <summary>
|
|
|
+/// Presents a control within a panel in which to zoom in and out and pan. The <see cref="Content"/> must be a <see cref="Layoutable"/>,
|
|
|
+/// and its <see cref="Layoutable.Width"/> and <see cref="Layoutable.Height"/> <b>must</b> be set.
|
|
|
+/// </summary>
|
|
|
[TemplatePart("PART_ZoomContent", typeof(ContentControl))]
|
|
|
[TemplatePart("PART_ZoomCanvas", typeof(Canvas))]
|
|
|
[TemplatePart("PART_ZoomContentBorder", typeof(Border))]
|
|
@@ -43,6 +48,28 @@ public partial class ZoomPanel : TemplatedControl
|
|
|
// Center of the image.
|
|
|
private Point ContentCentre = new();
|
|
|
|
|
|
+ public ZoomPanel()
|
|
|
+ {
|
|
|
+ this.GetPropertyChangedObservable(ContentProperty).Subscribe(ContentChanged);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ContentChanged(AvaloniaPropertyChangedEventArgs args)
|
|
|
+ {
|
|
|
+ if(Content is null) return;
|
|
|
+
|
|
|
+ void Update(AvaloniaPropertyChangedEventArgs? args = null)
|
|
|
+ {
|
|
|
+ if(OuterCanvas is not null)
|
|
|
+ {
|
|
|
+ PositionContent();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Update();
|
|
|
+ Content.GetPropertyChangedObservable(Layoutable.WidthProperty).Subscribe(Update);
|
|
|
+ Content.GetPropertyChangedObservable(Layoutable.HeightProperty).Subscribe(Update);
|
|
|
+ }
|
|
|
+
|
|
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
|
|
{
|
|
|
base.OnApplyTemplate(e);
|