.NETMAUI 上的 Flex Grow

huangapple go评论84阅读模式
英文:

Flex Grow on .NETMAUI

问题

I need a grow here. (我需要在这里添加 Grow。)

英文:

Im trying to add a Grow 1 on my .NET MAUI .cs file, can someone please steer me in the right direction, here is the code for the whole file..

Any help would be greatly appreciated! Thanks in advance .NETMAUI 上的 Flex Grow

using Microsoft.Maui.Layouts;
using Microsoft.Maui.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PagesDemo
{
    public class FlexDemo : ContentPage
    {
        public FlexDemo()
        {
            Content = new FlexLayout
            {
                Direction = FlexDirection.Column,

                Children = {
                    new Label
                    {
                        Text = "HEADER",
                        FontSize = 18,
                        BackgroundColor = Colors.Aqua,
                        HorizontalTextAlignment = TextAlignment.Center,
                    },

                    new FlexLayout
                    {
 // I need a grow here
                    }
                }
            };

        
        }
    }
}

答案1

得分: 1

new Label().Grow(1f);
var layout2 = new FlexLayout
{
    // contents
};

Content = new FlexLayout
{
    ...

    Children = {
        ...,
        layout2
    }
};

layout2.Grow(1f);
英文:

In FlexLayout extensions / Grow is this code snippet:

new Label().Grow(1f);

In your code:

  • above Content = ..., make a local variable holding what you want to grow.
  • Then add that variable to children.
  • Finally set Grow afterwards:
var layout2 = new FlexLayout
{
    // contents
};

Content = new FlexLayout
{
    ...

    Children = {
        ...,
        layout2
};

layout2.Grow(1f);

NOTE: It might be possible to move layout2.Grow.. line before Content = .... I haven't tried it.

huangapple
  • 本文由 发表于 2023年7月18日 05:07:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76708088.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定