【问题标题】:Xamarin.Forms iOS transparent ListView heading issueXamarin.Forms iOS 透明 ListView 标题问题
【发布时间】:2019-06-25 08:09:25
【问题描述】:

我正在制作一个简单的列表视图,但遇到了 iOS 标题问题 - 我想让它透明,但问题是,列表视图项目在标题下滑动。我想要实现的是,标题将与列表视图项目一起向上滑动。

This is how it looks now

这就是当前代码的样子:

                    <ListView  x:Name="SingleBeanView" 
                ItemsSource="{Binding Beans}" 
                IsGroupingEnabled="true"
                Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
                           BackgroundColor="Transparent">
                    <ListView.GroupHeaderTemplate>
                        <DataTemplate>
                            <ViewCell ios:Cell.DefaultBackgroundColor="Transparent" Height="52">
                                <Label Text="{Binding Heading}" TextColor="{StaticResource LightTextColor}" FontSize="Large" HorizontalOptions="Start" VerticalOptions="Start" Margin="15,10,0,0"/>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.GroupHeaderTemplate>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout BackgroundColor="Transparent" Orientation="Vertical">
                                    <StackLayout Orientation="Horizontal">
                                        <Label Text="{Binding Field1}"/>
                                        <Label Text="{Binding Field2}"/>
                                        <Label Text="{Binding Field3}"/>
                                    </StackLayout>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

【问题讨论】:

  • 可以通过在列表视图中添加上边距来解决吗?
  • 不,那样不行

标签: xamarin xamarin.forms xamarin.ios


【解决方案1】:

很遗憾,如果在ListView中使用GroupHeader,就达不到你想要的效果了。这个效果是苹果设计的。如果要修改,这需要更多的事情和时间来做自定义列表视图。

这里有一个 solution 用于原生 ios,您可以尝试使用 custom renderer 来做。但是,经过测试,这在 Xamarin 中无法使用。

所以最后一种方法可能需要自定义单元格来实现它——将标题放在 Cell 中。那么这意味着你不能使用GroupHeaderTemplate

Another discussion.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    • 2019-03-09
    • 1970-01-01
    相关资源
    最近更新 更多