【问题标题】:Drag and Drop on Xamarin Forms在 Xamarin 表单上拖放
【发布时间】:2020-11-26 18:11:27
【问题描述】:

我们希望在 Xamarin 表单中实现拖放功能

并且在这个用户中应该能够从一个地方拖动一个表情符号,然后放在另一个地方。不过,我们不希望源表情符号消失,并且应该能够知道对哪个员工进行评级。

Image how it is before

Image how it is after

问题也发布在: https://forums.xamarin.com/discussion/184104/drag-and-drop-on-xamarin-forms/p1?new=1

我们检查了以下几个链接,但似乎都没有工作:

Xamarin Forms Drag Image between Views https://blog.francois.raminosona.com/drag-and-drop-in-xamarin-forms/

如果能得到一些关于如何做的提示,即使这在表单上是可能的,将不胜感激?

【问题讨论】:

    标签: xamarin.forms drag-and-drop


    【解决方案1】:

    您可以检查下面的代码。

    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;
    
    
            }
    
        }
    

    截图:

    您可以查看代码项目中的源文件以供参考。 https://github.com/WendyZang/Test/tree/master/Drag_Drop_Controls/Xamarin-Developer-Sample-master

    【讨论】:

      猜你喜欢
      • 2017-01-06
      • 1970-01-01
      • 1970-01-01
      • 2020-09-15
      • 1970-01-01
      • 2020-06-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-02
      相关资源
      最近更新 更多