使用Maui XAML中的HorizontalStackLayout和VerticalStackLayout与grid结合使用。

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

using HorizontalStackLayout and VerticalStackLayout with grid on maui XAML

问题

尝试构建我的第一个MAUI MAXL(UI)应用程序
我有3个元素,它们使用HorizontalStackLayout和VerticalStackLayout组织
我想将它们作为一个结构使用,并将它们放在不同的位置使用网格
但是只有Grid.Column影响位置
我放置


并使用
Grid.Row="1" Grid.Column="1"来定位第一个块
以及
Grid.Row="2" Grid.Column="2"来定位第二个块

为什么只有列受到影响?

使用Maui XAML中的HorizontalStackLayout和VerticalStackLayout与grid结合使用。

<Grid RowDefinitions="100,200,300">
    <Grid ColumnDefinitions="100,200,300">
        <VerticalStackLayout
            Grid.Row="1" Grid.Column="1"
            Spacing="5"
            Padding="10,10"
            VerticalOptions="Center">
            <Label
                x:Name="Kitchen"
                Text="Kitchen"
                TextColor="Black"
                FontSize="20"
                Padding="30,0"
                VerticalOptions="Center"/>

            <HorizontalStackLayout
                Spacing="5"
                Padding="0,0"
                VerticalOptions="Center">

                <Button
                    HeightRequest="40"
                    WidthRequest="60"
                    Text="OFF"
                    BackgroundColor="Gray"
                    HorizontalOptions="Center"
                    Clicked="OnCounterClicked"/>
                
                <Button
                    HeightRequest="40"
                    WidthRequest="60"
                    Text="ON"
                    BackgroundColor="Green"
                    HorizontalOptions="Center"
                    Clicked="OnCounterClicked"/>
            </HorizontalStackLayout>
        </VerticalStackLayout>

        <VerticalStackLayout
            Grid.Row="2" Grid.Column="2"
            Spacing="5"
            Padding="10,10"
            VerticalOptions="Center">
            <Label
                x:Name="WorkRoom"
                Text="WorkRoom"
                TextColor="Black"
                FontSize="20"
                Padding="30,0"
                VerticalOptions="Center"/>

            <HorizontalStackLayout
                Spacing="5"
                Padding="0,0"
                VerticalOptions="Center">

                <Button
                    HeightRequest="40"
                    WidthRequest="60"
                    Text="OFF"
                    BackgroundColor="Gray"
                    HorizontalOptions="Center"
                    Clicked="OnCounterClicked"/>

                <Button
                    BindingContext="WorkRoom"
                    HeightRequest="40"
                    WidthRequest="60"
                    Text="ON"
                    BackgroundColor="Green"
                    HorizontalOptions="Center"
                    Clicked="OnCounterClicked"/>
            </HorizontalStackLayout>
        </VerticalStackLayout>
    </Grid>
</Grid>
英文:

trying to build my first MAUI MAXL (UI) app
i have 3 elements that are organized using HorizontalStackLayout and VerticalStackLayout
i want to use them as one struct and put them in a different location using grid
but only the Grid.Column is affecting the location
i put
<Grid RowDefinitions="100,200,300">
<Grid ColumnDefinitions="100,200,300">
and using
Grid.Row="1" Grid.Column="1" for 1 block
and
Grid.Row="2" Grid.Column="2" for the for second block

why only the Column is affected ?

使用Maui XAML中的HorizontalStackLayout和VerticalStackLayout与grid结合使用。

       &lt;Grid   RowDefinitions=&quot;100,200,300&quot;&gt;
&lt;Grid ColumnDefinitions=&quot;100,200,300&quot;&gt;
&lt;VerticalStackLayout
Grid.Row=&quot;1&quot; Grid.Column=&quot;1&quot;
Spacing=&quot;5&quot;
Padding=&quot;10,10&quot;
VerticalOptions=&quot;Center&quot;&gt;
&lt;Label
x:Name=&quot;Kitchen&quot;
Text=&quot;Kitchen&quot;
TextColor=&quot;Black&quot;
FontSize=&quot;20&quot;   
Padding=&quot;30,0&quot;
VerticalOptions=&quot;Center&quot;/&gt;
&lt;HorizontalStackLayout
Spacing=&quot;5&quot;
Padding=&quot;0,0&quot;
VerticalOptions=&quot;Center&quot;&gt;
&lt;Button
HeightRequest=&quot;40&quot;
WidthRequest=&quot;60&quot;
Text=&quot;OFF&quot;
BackgroundColor=&quot;Gray&quot;
HorizontalOptions=&quot;Center&quot;
Clicked=&quot;OnCounterClicked&quot;/&gt;
&lt;Button
HeightRequest=&quot;40&quot;
WidthRequest=&quot;60&quot;
Text=&quot;ON&quot;
BackgroundColor=&quot;Green&quot;
HorizontalOptions=&quot;Center&quot; 
Clicked=&quot;OnCounterClicked&quot;/&gt;
&lt;/HorizontalStackLayout&gt;
&lt;/VerticalStackLayout&gt;
&lt;VerticalStackLayout
Grid.Row=&quot;2&quot; Grid.Column=&quot;2&quot;
Spacing=&quot;5&quot;
Padding=&quot;10,10&quot;
VerticalOptions=&quot;Center&quot;&gt;
&lt;Label
x:Name=&quot;WorkRoom&quot;
Text=&quot;WorkRoom&quot;
TextColor=&quot;Black&quot;
FontSize=&quot;20&quot;   
Padding=&quot;30,0&quot;
VerticalOptions=&quot;Center&quot;/&gt;
&lt;HorizontalStackLayout
Spacing=&quot;5&quot;
Padding=&quot;0,0&quot;
VerticalOptions=&quot;Center&quot;&gt;
&lt;Button
HeightRequest=&quot;40&quot;
WidthRequest=&quot;60&quot;
Text=&quot;OFF&quot;
BackgroundColor=&quot;Gray&quot;
HorizontalOptions=&quot;Center&quot;
Clicked=&quot;OnCounterClicked&quot;/&gt;
&lt;Button
BindingContext=&quot;WorkRoom&quot;
HeightRequest=&quot;40&quot;
WidthRequest=&quot;60&quot;
Text=&quot;ON&quot;
BackgroundColor=&quot;Green&quot;
HorizontalOptions=&quot;Center&quot; 
Clicked=&quot;OnCounterClicked&quot;/&gt;
&lt;/HorizontalStackLayout&gt;
&lt;/VerticalStackLayout&gt;
&lt;/Grid&gt;
&lt;/Grid&gt;

答案1

得分: 1

你正在创建两个网格,一个嵌套在另一个内部。

<Grid RowDefinitions="100,200,300">
    <Grid ColumnDefinitions="100,200,300">

你(我认为)想要一个单独的网格。

<Grid RowDefinitions="100,200,300" ColumnDefinitions="100,200,300">
英文:

you are creating two Grids, one nested inside the other

&lt;Grid RowDefinitions=&quot;100,200,300&quot;&gt;
&lt;Grid ColumnDefinitions=&quot;100,200,300&quot;&gt;

you (I think) want a single grid

&lt;Grid RowDefinitions=&quot;100,200,300&quot; ColumnDefinitions=&quot;100,200,300&quot; &gt;

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

发表评论

匿名网友

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

确定