英文:
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"来定位第二个块
为什么只有列受到影响?
<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 ?
<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>
答案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
<Grid RowDefinitions="100,200,300">
<Grid ColumnDefinitions="100,200,300">
you (I think) want a single grid
<Grid RowDefinitions="100,200,300" ColumnDefinitions="100,200,300" >
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论