XAML 更改网格上按钮的大小XAMARIN

2nc8po8w  于 2023-05-21  发布在  其他
关注(0)|答案(3)|浏览(116)

我需要更改网格内按钮的大小。

当添加属性HightRequest和WidthRequest时,这不会在我的应用程序中进行任何更改...这就是为什么会发生?我应该怎么做才能修改网格上按钮的大小?
能帮我吗?
MyView.XAML:

<StackLayout
            Padding="5">
            <SearchBar
                    Placeholder="Buscar..."              
                    BackgroundColor="White">
            </SearchBar>

            <Grid HorizontalOptions="FillAndExpand">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="4*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>                
                </Grid.RowDefinitions>

                <Label
                            Grid.Column="0"
                            Grid.Row="0"
                            Text="(1537) CLORO, GAS LICUADO"
                             VerticalOptions="Center">
                </Label>
                <Button
                            Grid.Column="1"
                            Grid.Row="0"
                            Text="VER"
                            BackgroundColor="Orange"
                            TextColor="White"
                    HeightRequest="5"
                    WidthRequest="5">  
                </Button>
                <Button
                                Grid.Column="2"
                                Grid.Row="0"
                                Text="HDS"
                                BackgroundColor="Blue"
                                TextColor="White">

                </Button>

                <Label
                            Grid.Column="0"
                            Grid.Row="1"
                            Text="(11) ACTION 707"
                        VerticalOptions="Center">
                    </Label>
                    <Button
                            Grid.Column="1"
                            Grid.Row="1"
                            Text="VER"
                            BackgroundColor="Orange"
                            TextColor="White">
                    </Button>
                    <Button
                            Grid.Column="2"
                            Grid.Row="1"
                            Text="HDS"
                            BackgroundColor="Blue"
                            TextColor="White">
                    </Button>

            </Grid>

        </StackLayout>
hec6srdp

hec6srdp1#

<StackLayout
        Padding="5">
    <SearchBar
                Placeholder="Buscar..."              
                BackgroundColor="White">
    </SearchBar>

    <Grid HorizontalOptions="FillAndExpand">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Label
                        Grid.Column="0"
                        Grid.Row="0"
                        Text="(1537) CLORO, GAS LICUADO"
                         VerticalOptions="Center">
        </Label>
        <Button
                        Grid.Column="1"
                        Grid.Row="0"
                        Text="VER"
                        BackgroundColor="Orange"
                        TextColor="White"
                HeightRequest="50"
                WidthRequest="120">
        </Button>
        <Button
                            Grid.Column="2"
                            Grid.Row="0"
                            Text="HDS"
                            BackgroundColor="Blue"
                            TextColor="White"
            HeightRequest="50"
            WidthRequest="90">

        </Button>

        <Label
                        Grid.Column="0"
                        Grid.Row="1"
                        Text="(11) ACTION 707"
                    VerticalOptions="Center">
        </Label>
        <Button
                        Grid.Column="1"
                        Grid.Row="1"
                        Text="VER"
                        BackgroundColor="Orange"
                        TextColor="White">
        </Button>
        <Button
                        Grid.Column="2"
                        Grid.Row="1"
                        Text="HDS"
                        BackgroundColor="Blue"
                        TextColor="White">
        </Button>

    </Grid>

</StackLayout>

g6ll5ycj

g6ll5ycj2#

您可以通过在Grid中更改ColumnDefinition的宽度来完成此操作。第二行也不在网格中,因为只有一个RowDefinition

vyswwuz2

vyswwuz23#

你必须把一个堆栈布局在网格布局。使用网格。Column/ grid.row来定位堆栈布局。将您希望调整大小的元素放在堆栈布局中,该布局将接受其中元素的宽度请求。

相关问题