Drag And Drop Avalonia C#

Задача состоит в том, чтобы реализовать на AvaloniaUI минимальный пример Drag & Drop. В моем случае сделана попытка перемещать красный прямоугольник по Canvas. Подскажите, пожалуйста, чего не хватает для работы примера? MainView.axaml

<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:vm="clr-namespace:CanvasTest.ViewModels"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
             Width="800" Height="450"
             x:Class="CanvasTest.Views.MainView"
             x:DataType="vm:MainViewModel"
             DragDrop.AllowDrop="True">
    <Design.DataContext>
        <vm:MainViewModel />
    </Design.DataContext>
    <Canvas Name="canvas" Width="600" Height="400" DragDrop.AllowDrop="True" Background="Transparent">
        <Rectangle DragDrop.AllowDrop="True" PointerPressed="OnPointerPressed" Fill="Red" Height="100" Width="100"/>
    </Canvas>
</UserControl>

MainView.axaml.cs

public partial class MainView : UserControl
{
    public MainView()
    {
        InitializeComponent();
        AddHandler(DragDrop.DragOverEvent, DragOver);
        AddHandler(DragDrop.DropEvent, Drop);
    }
    private async void OnPointerPressed(object? sender, PointerPressedEventArgs e)
    {
        var mousePos = e.GetPosition(canvas);
        var dragData = new DataObject();
        var result = await DragDrop.DoDragDrop(e, dragData, DragDropEffects.Move);
    }
 
    private void DragOver(object? sender, DragEventArgs e)
    {
        e.DragEffects = DragDropEffects.Move;
    }
 
    private void Drop(object? sender, DragEventArgs e)
    {
        e.DragEffects = DragDropEffects.Move;
    }
}

MainWindow.axaml

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:CanvasTest.ViewModels"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:views="clr-namespace:CanvasTest.Views"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        Width="800" Height="450"
        x:Class="CanvasTest.Views.MainWindow"
        Icon="/Assets/avalonia-logo.ico"
        Title="CanvasTest"
        DragDrop.AllowDrop="True">
        <views:MainView />
</Window>

Ответы (0 шт):