简体   繁体   English

如何使分组的ListView标头在iOS中正确浮动(不发粘)?

[英]How to make grouped ListView headers floating (not sticky) correctly in iOS?

I have a grouped ListView (Xamarin Forms). 我有一个分组的ListView(Xamarin表单)。 I need to make group headers floating (not sticky). 我需要使组标题浮动 (不发粘)。 On Android everything works the way I want, but on iOS there is a problem. 在Android上,一切都按我想要的方式运行,但是在iOS上,则存在问题。

I tried to use this: https://forums.xamarin.com/discussion/34696/listview-grouped-style-on-ios 我试图用这个: https : //forums.xamarin.com/discussion/34696/listview-grouped-style-on-ios

In this case headers are floating, but it looks like it creates new control and the previous one doesn't disappear. 在这种情况下,标头是浮动的,但看起来它创建了新控件,而上一个控件没有消失。 I mean that I see one list which overlaps another one. 我的意思是我看到一个列表与另一个列表重叠。

I can set the background of the top list to some color. 我可以将顶部列表的背景设置为某种颜色。 Then the list that is behind will be not visible, but it is not the solution for this problem. 然后,后面的列表将不可见,但这不是解决此问题的方法。 Can somebody explain me how to fix this? 有人可以解释一下该如何解决吗?

A simple solution to this problem is to use an iOS platform-specific feature for Xamarin.Forms that allows you to easily set the ListView Group Header Style in XAML (or code behind) in one line as follows: 一个简单的解决方案是使用Xamarin.Forms的iOS平台特定功能,该功能使您可以轻松地在XAML中(或在后面的代码中)在一行中设置ListView组标题样式,如下所示:

<ContentPage ...
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core">
    <StackLayout Margin="20">
        <ListView ios:ListView.GroupHeaderStyle="Grouped">
            ...
        </ListView>
    </StackLayout>
</ContentPage>

The 'Grouped' enumeration indicates that header cells do not float when the ListView is scrolled. “分组”枚举表示滚动ListView时标头单元格不浮动。 See https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/ios/listview-group-header-style for further details. 有关更多详细信息,请参见https://docs.microsoft.com/zh-cn/xamarin/xamarin-forms/platform/ios/listview-group-header-style

Did you refer the doc from here ? 您是否从这里引用了文档?

If you want to make group headers floating you just need to set the IsGroupingEnabled as true . 如果要使组头浮动,则只需将IsGroupingEnabled设置为true即可。

in xaml 在xaml中

<ListView x:Name ="listView" IsGroupingEnabled="true" GroupDisplayBinding="{Binding LongName}" >
   <ListView.ItemTemplate>
    <DataTemplate>
      <TextCell Text="{Binding Name}" Detail = "{Binding Comment}" />
    </DataTemplate>
   </ListView.ItemTemplate>
</ListView>

in code behind 在后面的代码中

public partial class GroupedListXaml : ContentPage
{
    private ObservableCollection<GroupedVeggieModel> grouped { get; set; }
    public GroupedListXaml ()
    {
     InitializeComponent ();

     grouped = new ObservableCollection<GroupedVeggieModel> ();
     var veggieGroup = new GroupedVeggieModel () { LongName = "vegetables" };
     var fruitGroup = new GroupedVeggieModel () { LongName = "fruit" };

     veggieGroup.Add (new VeggieModel () { Name = "celery", Comment = "try ants on a log" });
     veggieGroup.Add (new VeggieModel () { Name = "tomato",  Comment = "pairs well with basil" });
     veggieGroup.Add (new VeggieModel () { Name = "zucchini", Comment = "zucchini bread > bannana bread" });
     veggieGroup.Add (new VeggieModel () { Name = "peas",  Comment = "like peas in a pod" });
     veggieGroup.Add (new VeggieModel () { Name = "celery", Comment = "try ants on a log" });
     veggieGroup.Add (new VeggieModel () { Name = "tomato",  Comment = "pairs well with basil" });
     veggieGroup.Add (new VeggieModel () { Name = "zucchini", Comment = "zucchini bread > bannana bread" });
     veggieGroup.Add (new VeggieModel () { Name = "peas",  Comment = "like peas in a pod" });
     veggieGroup.Add (new VeggieModel () { Name = "celery", Comment = "try ants on a log" });
     veggieGroup.Add (new VeggieModel () { Name = "tomato",  Comment = "pairs well with basil" });
     veggieGroup.Add (new VeggieModel () { Name = "zucchini", Comment = "zucchini bread > bannana bread" });
     veggieGroup.Add (new VeggieModel () { Name = "peas",  Comment = "like peas in a pod" });

     fruitGroup.Add (new VeggieModel () {Name = "banana", Comment = "available in chip form factor"});
     fruitGroup.Add (new VeggieModel () {Name = "strawberry", Comment = "spring plant"});
     fruitGroup.Add (new VeggieModel () {Name = "cherry",Comment = "topper for icecream"});
     fruitGroup.Add (new VeggieModel () {Name = "banana", Comment = "available in chip form factor"});
     fruitGroup.Add (new VeggieModel () {Name = "strawberry", Comment = "spring plant"});
     fruitGroup.Add (new VeggieModel () {Name = "cherry",Comment = "topper for icecream"});
     fruitGroup.Add (new VeggieModel () {Name = "banana", Comment = "available in chip form factor"});
     fruitGroup.Add (new VeggieModel () {Name = "strawberry", Comment = "spring plant"});
     fruitGroup.Add (new VeggieModel () {Name = "cherry",Comment = "topper for icecream"});


     grouped.Add (veggieGroup);
     grouped.Add (fruitGroup);
     listView.ItemsSource = grouped;
  }
}


in ViewModel 在ViewModel中

 public class VeggieModel
 {
  public string Name { get; set; }
  public string Comment { get; set; }       
  public VeggieModel ()
  {
  }
 }

  public class GroupedVeggieModel : ObservableCollection<VeggieModel>
  {
    public string LongName { get; set; }
  }

在此处输入图片说明

If I misunderstood your issue.You can provide a screenshot or gif which contains your issue.It is helpful to solve your problem. 如果我误解了您的问题,可以提供包含您问题的屏幕截图或gif。这有助于解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xamarin表单 - 如何使用标题生成iOS ListView本机分组样式? - Xamarin Forms - How to Make iOS ListView Native Grouped Style With Headers? 如何在iOS7的UICollectionView中制作粘性标头? - How to make sticky headers in UICollectionView on iOS7? 如何在Android中制作粘性节标题(如iOS)? - How to make sticky section headers (like iOS) in Android? iOS - 带有自定义单元格的分组 UITableView 中的粘性部分标题 - iOS - Sticky section headers in grouped UITableView with custom cells 如何在Xcode中正确使用iOS运行时标头? - How to correctly use iOS Runtime Headers in Xcode? 如何使用ios-charts制作分组的BarChart? - How to make a grouped BarChart with ios-charts? Mapbox iOS SDK 3.1 如何使注释标注具有粘性 - Mapbox iOS SDK 3.1 How to make Annotation Callout sticky 如何使用“用户标头搜索路径”使Xcode正确找到标头? - How to make Xcode correctly find the headers, using the “User headers search paths”? iOS - 带有内容插入的粘性标题 - 标题视图不像单元格那样滚动 - iOS - Sticky headers with content inset - Header view is not scrolling like the cell 仅在iOS上,粘贴的表格标题在滚动后会松开 - On iOS only, sticky table headers come unstuck after scrolling
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM