【问题标题】:change the size of a button on a grid XAMARIN更改网格 XAMARIN 上按钮的大小
【发布时间】:2019-02-08 20:27:57
【问题描述】:

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

当添加属性 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>

【问题讨论】:

  • 行索引 1 超出网格行定义范围 (0-0)
  • 您想在我的网格中添加另一个元素 吗?或更改 GRID.ROWS? @toumir
  • 如果我理解正确,您想在列表中显示搜索结果,每个项目列表都有一个标签和两个按钮?还是行是固定的?
  • 在这种情况下...该行是固定的@toumir

标签: xaml xamarin button gridview xamarin.forms


【解决方案1】:
<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>

【讨论】:

    【解决方案2】:

    您可以通过更改网格中ColumnDefinition 的宽度来做到这一点。 此外,您的第二行不在网格中,因为您只有一个 RowDefinition

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多