Xamarin Forms - Plusieurs vues sur une page [fermé]

Dec 09 2020

J'ai donc besoin de réaliser plusieurs vues sur une page , quelque chose comme ça , mais je n'arrive pas à trouver un moyen qui rend cette multiplateforme possible. Je peux voir que sur IOS, vous pouvez y parvenir en ajoutant plusieurs contrôleurs de vue à une page, mais est-ce réalisable dans les formulaires xamarin?

S'il vous plaît laissez-moi savoir si vous avez une expérience avec cela.

Merci d'avance!

Réponses

LucasZhang-MSFT Dec 09 2020 at 18:21

Il existe de nombreuses solutions qui peuvent la mettre en œuvre. Par exemple, vous pouvez utiliser AbsoluteLayout pour créer une vue par balayage.

dans ContentPage

<AbsoluteLayout BackgroundColor="White" AbsoluteLayout.LayoutBounds="0,1,1,1">
        <!--  -->

        <Button Clicked="Button_Clicked" Text="Test"  AbsoluteLayout.LayoutBounds="0.5,0.3,0.2,0.05" AbsoluteLayout.LayoutFlags="All" />

        <StackLayout x:Name="bottomBar" BackgroundColor="Olive" AbsoluteLayout.LayoutBounds="0.5,1.0,1.0,0.04" AbsoluteLayout.LayoutFlags="All">
            

            <!-- put the content of swipe here -->

        </StackLayout>
    </AbsoluteLayout>

Dans le code derrière

    bool isShow;
    const double layoutPropHeightMax = 0.45;
    const double layoutPropHeightMin = 0.06;
   //you could set the height here as you want

    private void Button_Clicked(object sender, EventArgs e)
    {
        if(!isShow)
        {
            //show the keyboard

            Device.BeginInvokeOnMainThread(async () =>
            {

                var height = layoutPropHeightMin;

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

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

            });

        }

        else
        {
            // hide the keyboard
            Device.BeginInvokeOnMainThread(async () =>
            {

                var height = layoutPropHeightMax;

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

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

            });

        }


        isShow = !isShow;
    }

Voici un problème similaire que vous pouvez avoir une référence.