Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Xamarin Forms - How to Make iOS ListView Native Grouped Style With Headers?

$
0
0

I also asked this on stackoverflow but haven't got any answers. I feel this should be easy but it is not working.

To see my images you will have to check the stackoverflow post as I'm unable to post images as it says I can't have links.

stackoverflow(com)/questions/47851691/xamarin-forms-how-to-make-ios-listview-native-grouped-style-with-headers

I have created a listview in Xamarian Forms using MVVM and binding to create a grouped listview.I would like the listview to have the UITableView Style group which is for iOS. I tried creating this via a custom renderer which I found online, but the result looks wrong as everything is gray.

The xaml page is as follows:

<StackLayout Spacing="0">
    <SearchBar x:Name="SearchBarControl" Text="{Binding SearchText}" SearchCommand="{Binding SearchCommand}" Placeholder="Search"></SearchBar>
    <ListView x:Name="HistoryList" IsGroupingEnabled="True" GroupDisplayBinding="{Binding Title}" ItemsSource="{Binding History}" CachingStrategy="RecycleElement">
        <ListView.ItemTemplate>
            <DataTemplate>
                <TextCell Text="{Binding TagContent}" Detail="{Binding DateAndTime}" />
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackLayout>

The custom renderer that I believe should make it grouped:

                 [assembly: ExportRenderer(typeof(ListView), typeof(iOSListViewCustomRenderer))]
                 namespace Test.iOS.CustomRenderer
                 {
                     public class iOSListViewCustomRenderer : ListViewRenderer
                     {
                         protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
                         {
                             base.OnElementChanged(e);
                             if (this.Control != null && e.NewElement != null)
                             {
                                 var tbl = new UITableView(this.Bounds, UITableViewStyle.Grouped)
                                 {
                                     Source = this.Control.Source,
                                 };

                                 this.SetNativeControl(tbl);
                             }
                         }
                     }
                 }

If anyone needs to see anything else, let me know.

I know the tableview control in forms gives me the proper look but it seems to be static content and not dynamic info from a SQL database.

I tried making the cells white by making a custom cell but that didn't change anything.

How can I get the xamarin forms list view to look like the native grouped style with the cells being white and be in that styled group?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>