【问题标题】:Xamarin.Forms ListView ViewCell issue on iOSiOS 上的 Xamarin.Forms ListView ViewCell 问题
【发布时间】:2015-04-28 20:07:24
【问题描述】:

我一直试图在 Xaml (x.forms) 中使它看起来正确,但无法使其正常工作。在没有自定义单元格渲染器的情况下,任何可能的方法都可以在 Xaml 中解决?

这是它在原生 iOS 上的外观:

到目前为止我在 Xaml 中得到了什么:

这是我的 Xaml:

<ScrollView>
    <StackLayout>
        <ActivityIndicator IsRunning="{Binding IsFetching}" />
        <ListView ItemsSource="{Binding Events}" Header="2015" Footer="">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell Height="55">
                        <ViewCell.View>
                            <StackLayout Orientation="Horizontal" Padding="5" BackgroundColor="White">                                                          
                                <StackLayout>
                                    <BoxView WidthRequest="44" 
                                         HeightRequest="5"  
                                         BackgroundColor="Purple"
                                         />
                                    <Label Text="AUG" FontSize="12" HeightRequest="13" HorizontalOptions="Center" VerticalOptions="Start" FontAttributes="Bold"/>
                                    <Label Text="31" FontSize="13" VerticalOptions="StartAndExpand" HorizontalOptions="Center" />
                                </StackLayout>                              
                                <StackLayout Orientation="Vertical"
                                             HorizontalOptions="StartAndExpand">
                                    <Label Text="Relay For Life of" FontSize="14" VerticalOptions="End" TextColor="Gray"/>
                                    <Label Text="Hope City" FontSize="16" FontAttributes="Bold" VerticalOptions="StartAndExpand"/>
                                </StackLayout>
                            </StackLayout>
                        </ViewCell.View>
                    </ViewCell>         
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ScrollView>

【问题讨论】:

    标签: ios xaml xamarin xamarin.forms


    【解决方案1】:

    您可以尝试使用 Grid 而不是 Stack,也可以将 RowHeight 添加到您的 ListView

    <ListView ... RowHeight="55">
     ...
     <ViewCell Height="55">
       <Grid> 
         <Grid.ColumnDefinitions>
           <ColumnDefinition Width="44"/>
           <ColumnDefinition Width="*"/>
           <ColumnDefinition Width="44"/> <!-- for the checkmark -->
         </Grid.ColumnDefinitions>
         <Grid Grid.Column="0">
           <Grid.RowDefinitions>
              <RowDefinition Height="5" />
              <RowDefinition Height="22" />
              <RowDefinition Height="17" />
           </Grid.RowDefinitions>
           <BoxView Grid.Row="0" WidthRequest="44" HeightRequest="5" BackgroundColor="Purple"/>
           <!-- experiment with the vertical alignment to get it right -->
           <Label Grid.Row="1" Text="AUG" .../>
           <Label Grid.Row="2" Text="31" .../>
         </Grid>
    <Grid Grid.Column="0">
           <Grid.RowDefinitions>
              <RowDefinition Height="22" />
              <RowDefinition Height="22" /> 
           </Grid.RowDefinitions> 
           <!-- if the vertical alignment doesn't work well add two more rows for top and bottom padding -->
           <Label Grid.Row="0" Text="Relay for life" VerticalOptions="End" .../>
           <Label Grid.Row="1" Text="Hope city" VerticalOptions="Start" .../>
         </Grid>
       </Grid>
     </ViewCell>
    

    【讨论】:

      【解决方案2】:

      在 ListView 上设置 HasUnevenRows="True"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-24
        • 2018-06-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多