mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 14:46:31 +00:00
move Windows app to Windows folder, create folder for Web, create simplest web api service
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Azaion.Annotator.Extensions;
|
||||
|
||||
public static class CanvasExtensions
|
||||
{
|
||||
public static readonly DependencyProperty PercentPositionProperty =
|
||||
DependencyProperty.RegisterAttached("PercentPosition", typeof(Point), typeof(CanvasExtensions),
|
||||
new PropertyMetadata(new Point(0, 0), OnPercentPositionChanged));
|
||||
|
||||
public static readonly DependencyProperty PercentSizeProperty =
|
||||
DependencyProperty.RegisterAttached("PercentSize", typeof(Point), typeof(CanvasExtensions),
|
||||
new PropertyMetadata(new Point(0, 0), OnPercentSizeChanged));
|
||||
|
||||
private static void OnPercentSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static void SetPercentPosition(DependencyObject obj, Point value) => obj.SetValue(PercentPositionProperty, value);
|
||||
|
||||
private static void OnPercentPositionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (!(d is FrameworkElement element)) return;
|
||||
if (!(VisualTreeHelper.GetParent(element) is Canvas canvas)) return;
|
||||
|
||||
canvas.SizeChanged += (s, arg) =>
|
||||
{
|
||||
var percentPosition = (Point)element.GetValue(PercentPositionProperty);
|
||||
var xPosition = percentPosition.X * canvas.ActualWidth - element.ActualWidth / 2;
|
||||
var yPosition = percentPosition.Y * canvas.ActualHeight - element.ActualHeight / 2;
|
||||
Canvas.SetLeft(element, xPosition);
|
||||
Canvas.SetTop(element, yPosition);
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user