是否可以使用Xamarin表单将面板滑块向下拖动? xaml 在后面的代码中

我是xamamrin的新手,任何人都可以帮助我将其向下拖动到面板滑块上。 我想使用Xamarin表单将android中的滑块向下拖动 mentioned in image

任何人都想分享兔子。

YOZA007 回答:是否可以使用Xamarin表单将面板滑块向下拖动? xaml 在后面的代码中

有很多实现滑动面板的方法,我提供了其中一种使用PanGestureRecognizer的方法:

xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"         
             mc:Ignorable="d"
             x:Class="App10.MainPage">

    <AbsoluteLayout BackgroundColor="White" AbsoluteLayout.LayoutBounds="0,1,1">
        <!--  -->
        <StackLayout x:Name="bottomDrawer" BackgroundColor="Olive" AbsoluteLayout.LayoutBounds="0.5,0.00,0.9,0.04" AbsoluteLayout.LayoutFlags="All">
            <StackLayout.GestureRecognizers>
                <PanGestureRecognizer PanUpdated="PanGestureHandler" />
            </StackLayout.GestureRecognizers>

            <!-- put the content of panel slider here -->

        </StackLayout>
    </AbsoluteLayout>

</ContentPage>

在后面的代码中


using System.ComponentModel;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace App10
{
    // Learn more about making custom code visible in the Xamarin.Forms previewer
    // by visiting https://aka.ms/xamarinforms-previewer
    [DesignTimeVisible(false)]
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();        
        }

        double? layoutHeight;
        double layoutBoundsHeight;
        int direction;
        const double layoutPropHeightMax = 0.75;
        const double layoutPropHeightMin = 0.04;
        void PanGestureHandler(object sender,PanUpdatedEventArgs e)
        {
            layoutHeight = layoutHeight ?? ((sender as StackLayout).Parent as AbsoluteLayout).Height;
            switch (e.StatusType)
            {
                case GestureStatus.Started:
                    layoutBoundsHeight = AbsoluteLayout.GetLayoutBounds(sender as StackLayout).Height;
                    break;
                case GestureStatus.Running:
                    direction = e.TotalY > 0 ? 1 : -1;
                    break;
                case GestureStatus.Completed:
                    if (direction > 0) 
                    {
                        Device.BeginInvokeOnMainThread(async() =>
                        {

                            var height = layoutPropHeightMin;

                            while (height < layoutPropHeightMax)
                            {
                               await Task.Delay(2);
                                height += 0.04;

                                AbsoluteLayout.SetLayoutBounds(bottomDrawer,new Rectangle(0.5,height));
                            }

                        });

                    }
                    else
                    {
                        Device.BeginInvokeOnMainThread(async () =>
                        {

                            var height = layoutPropHeightMax;

                            while (height > layoutPropHeightMin)
                            {
                                await Task.Delay(2);
                                height -= 0.04;

                                AbsoluteLayout.SetLayoutBounds(bottomDrawer,height));
                            }

                        });
                    }
                    break;
            }
        }
    }
}

enter image description here

本文链接:https://www.f2er.com/2901069.html

大家都在问