Перетаскивание в формах Xamarin - PullRequest
2 голосов
/ 06 августа 2020

Мы хотим реализовать функцию перетаскивания в формах Xamarin

, и в этом случае пользователь должен иметь возможность перетаскивать эмодзи из одного места и помещать в другое. Однако мы не хотим, чтобы исходный смайлик go был удален, и мы должны иметь возможность узнать, для какого сотрудника выставлен рейтинг.

Изображение, как оно было раньше

Изображение после

Вопрос также размещен на: https://forums.xamarin.com/discussion/184104/drag-and-drop-on-xamarin-forms/p1?new=1

Мы проверили несколько ссылок, как показано ниже, но ни один из них, похоже, не работает:

Xamarin Forms Перетаскивайте изображение между представлениями https://blog.francois.raminosona.com/drag-and-drop-in-xamarin-forms/

Буду признателен, если вы сможете получить несколько советов о том, как сделать это, и даже если бы это было возможно в формах?

1 Ответ

1 голос
/ 07 августа 2020

Вы можете проверить код ниже.

xaml:

<StackLayout Margin="10">

        <StackLayout Margin="10" Orientation="Horizontal">
            <components:DragAndDropSample3ReceivingView
                BackgroundColor="Beige"
                HeightRequest="80"
                WidthRequest="80" />
            <components:DragAndDropSample3ReceivingView
                BackgroundColor="Beige"
                HeightRequest="80"
                WidthRequest="80" />
            <components:DragAndDropSample3ReceivingView
                BackgroundColor="Beige"
                HeightRequest="80"
                WidthRequest="80" />

        </StackLayout>
        <BoxView
            BackgroundColor="Blue"
            HeightRequest="5"
            WidthRequest="3" />
        <StackLayout Margin="10" Orientation="Horizontal">

            <components:DragAndDropSample3MovingView
                BackgroundColor="Red"
                CornerRadius="40"
                HeightRequest="40"
                WidthRequest="40" />
            <components:DragAndDropSample3MovingView
                BackgroundColor="Green"
                CornerRadius="40"
                HeightRequest="40"
                WidthRequest="40" />
        </StackLayout>

    </StackLayout>

Код позади:

 public void OnDropReceived(IDragAndDropMovingView view)
    {
        if (view is DragAndDropSample3MovingView sender)
        {
            var control = new DragAndDropSample3MovingView()
            {
               BackgroundColor=sender.BackgroundColor,
               CornerRadius=sender.CornerRadius,
               WidthRequest=sender.WidthRequest,
               HeightRequest=sender.HeightRequest,                 
              
            };
            Content = control;


        }

    }

Снимок экрана:

enter image description here

You could check the source file from the code project for reference. https://github.com/WendyZang/Test/tree/master/Drag_Drop_Controls/Xamarin-Developer-Sample-master

...