【问题标题】:Xamarin forms button with Gridview带有 Gridview 的 Xamarin 表单按钮
【发布时间】:2018-05-02 16:07:32
【问题描述】:

我的 xamarin 视图中有一个旋转木马。网格视图内的旋转木马。还有一个按钮,但问题是按钮没有到达正确的位置。我想将注册按钮稍微向上和全宽。

这是我的看法

我的代码

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:InfutureMob"
         x:Class="InfutureMob.MainPage"
         xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView">

    <Grid RowSpacing="0" Grid.RowSpan="2">
        <!--<Grid.RowDefinitions>
            <RowDefinition Height=".3*"/>
            <RowDefinition Height=".7*"/>
        </Grid.RowDefinitions>-->
    <Grid.RowDefinitions>
        <RowDefinition Height="5*"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="5*"/>
    </Grid.RowDefinitions>
    <cv:CarouselView ItemsSource="{Binding Zoos}" x:Name="CarouselImages" >
            <cv:CarouselView.ItemTemplate>
                <DataTemplate>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Image Grid.RowSpan="2" Aspect="AspectFill" Source="{Binding ImageUrl}"/>
                    <StackLayout Grid.Row="1" BackgroundColor="#80000000" Padding="12">
                        <Label TextColor="White" Text="{Binding Name}" FontSize="16" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
                    </StackLayout>

                </Grid>

            </DataTemplate>
            </cv:CarouselView.ItemTemplate>
        </cv:CarouselView>
    <StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand"  Margin="20,20,20,0" Grid.Row="2">


        <Button Text="Register" BackgroundColor="#3897f0" TextColor="White" HeightRequest="50" VerticalOptions="Start" />

    </StackLayout>
</Grid></ContentPage>

【问题讨论】:

    标签: c# xaml xamarin xamarin.forms


    【解决方案1】:

    有几件事很突出...... 首先,为网格定义 3 行,但包含 Button 的 StackLayout 位于 Grid.Row="2" 中,如果它需要位于 Carousel 下方,则应为 1。 (为了提高可读性,将 Grid.Row="0" 放在 Carousel 上)

    其次,您不需要使用 StackLayout 包装按钮并将 Horizo​​ntalOptions 放入 FillAndExpand 以使按钮填充 Grid 的整个大小。

    【讨论】:

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