拖放 .Net Maui

Drag and Drop .Net Maui

有没有办法在新的 .net Maui 移动应用程序(Android、Ios 和 WinApp?

中创建带有可拖动项目的布局

我一直在搜索平台上可以做什么,但目前还没有找到。

是的,使用 CanDrag 和 AllowDrop。

在这里找到DragdropMaui example

在MainPage.xaml

    <Frame Margin="20">
        <Frame.GestureRecognizers>
            <DropGestureRecognizer AllowDrop="True" Drop="DropGestureRecognizer_Drop_1" />
        </Frame.GestureRecognizers>
    </Frame>

            <Label Text="Drag Me away" HorizontalTextAlignment="Center" TextColor="Black" FontSize="36">
                <Label.GestureRecognizers>
                    <DragGestureRecognizer CanDrag="True" DragStarting="DragGestureRecognizer_DragStarting_1" />
                </Label.GestureRecognizers>
            </Label>

在MainPage.cs

 private void DragGestureRecognizer_DragStarting_1(object sender, DragStartingEventArgs e)
{
    var label = (sender as Element)?.Parent as Label;
    e.Data.Properties.Add("Text", label.Text);
}

private void DropGestureRecognizer_Drop_1(object sender, DropEventArgs e)
{
    var data = e.Data.Properties["Text"].ToString();
    var frame = (sender as Element)?.Parent as Frame;
    frame.Content = new Label
    {
        Text = data
    };
}