我有一個帶有 GroupHeader 的 Xamarin Forms Listview:
<ListView x:Name="listView"
ios:ListView.SeparatorStyle="FullWidth"
AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All"
ItemsSource="{Binding Items}"
IsGroupingEnabled="true"
SeparatorVisibility="Default"
IsPullToRefreshEnabled="False"
SeparatorColor="Red"
SelectionMode="None"
Footer=""
BackgroundColor="Transparent">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<TextCell Text="Header Cell"/>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="Item Cell"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
在 iOS 上,分隔線(紅色)僅在專案之間可見,但在標題和專案之間不可見:

在 Android 上,這條線也在 Header 和 items 之間:
我只發現了一些洗掉 iOS 上分隔線的建議(設定 SeparatorColor 透明)。
如何在 iOS 上獲得 android 行為?
uj5u.com熱心網友回復:
你可以使用BoxView來達到你想要的效果,修改你的代碼如下:
<ListView x:Name="listView"
AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All"
ItemsSource="{Binding Items}"
IsGroupingEnabled="True"
SeparatorVisibility="None"
SelectionMode="None"
Footer=""
BackgroundColor="Transparent">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="Header Cell" Margin="0,10,0,0"/>
<BoxView HeightRequest="0.5" Color="Red" HorizontalOptions="FillAndExpand" Margin="0,8,0,0"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="Item Cell" Margin="0,10,0,0"/>
<BoxView HeightRequest="0.5" Color="Red" HorizontalOptions="FillAndExpand" Margin="0,5,0,0"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/527608.html
