Bug 56250 - GroupDisplayBinding fails on iPhone for ListView
Summary: GroupDisplayBinding fails on iPhone for ListView
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.3.4
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-05-11 21:13 UTC by Andy
Modified: 2017-12-11 07:08 UTC (History)
8 users (show)

Tags: ac binding linker groupdisplayname ios
Is this bug a regression?: ---
Last known good build:


Attachments
repro project (231.25 KB, application/zip)
2017-06-05 21:15 UTC, Jimmy [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 56250 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Andy 2017-05-11 21:13:44 UTC
NOTE: It DOES work on the iOS Simulator, but it does not work on the iPhone

When my ListView is set to grouping enabled, the GroupHeader text does not show on the iPhone. It shows in UWP, Android, and iOS Simulator . I am using an IGrouping<string, MyCustomClass> for the header.

I tried fixing 

You can test the bug by putting this code in with a ListView and deploying to your iPhone.

{
	//create list view
	...
        //GroupDisplayBinding = new Binding ("Key"), does not work, try work around
	GroupHeaderTemplate = new DataTemplate(typeof(GroupHeaderCell))
	...
}

private class GroupHeaderCell : TextCell
{
	//public GroupHeaderCell ()
	//{
        //Bug in Xamarin.Forms keeps this from working on iOS
        //this.SetBinding (TextProperty, nameof(IGrouping<string, MyCustomClass>.Key), BindingMode.OneWay);
	//}

	protected override void OnBindingContextChanged ()
	{
		base.OnBindingContextChanged ();

		var thing = (BindingContext as IGrouping<string, MyCustomClass>);
		if (thing != null) 
                {
                  Text = thing.Key;	
		}
	}
}


Xamarin Studio Community
Version 6.3 (build 863)
Installation UUID: 0b70f7ee-472a-47eb-9b2f-d467ed4e77ad
Runtime:
	Mono 5.0.0.100 (2017-02/9667aa6) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 500000100

NuGet
Version: 3.5.0.0

Xamarin.Profiler
Version: 1.5.4
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Xamarin.Android
Version: 7.3.0.13 (Xamarin Studio Community)
Android SDK: /Users/andymartin/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.3   (API level 18)
		4.4   (API level 19)
		5.1   (API level 22)
		6.0   (API level 23)
		7.0   (API level 24)
		7.1   (API level 25)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.5
SDK Build Tools Version: 25.0.3

Java SDK: /usr
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Xamarin Inspector
Version: 1.2.2
Hash: b71b035
Branch: d15-1
Build date: Fri, 21 Apr 2017 17:57:12 GMT

Apple Developer Tools
Xcode 8.3.2 (12175)
Build 8E2002

Xamarin.iOS
Version: 10.10.0.33 (Xamarin Studio Community)
Hash: 3e5ac5ff
Branch: d15-2
Build date: 2017-05-05 18:11:38-0400

Xamarin.Mac
Version: 3.4.0.33 (Xamarin Studio Community)

Build Information
Release ID: 603000863
Git revision: a2163670efe259c85cd8f335d95b175068fbbe2a
Build date: 2017-04-03 14:33:15-04
Xamarin addins: 2045d688ea1420e0381b473360ca62a763eb7d04
Build lane: monodevelop-lion-d15-1

Operating System
Mac OS X 10.12.4
Darwin Andy-Martins-MacBook-Pro.local 16.5.0 Darwin Kernel Version 16.5.0
    Fri Mar  3 16:52:33 PST 2017
    root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
Comment 1 Jimmy [MSFT] 2017-05-12 22:31:53 UTC
I just tested this by running the ListView Grouping sample[1] on an iOS 10.3 device and I could not reproduce the issue.

The sample project uses the GroupDisplayBinding as mentioned in the description and I could see the group headers in the ListView when the app was running. I tested using both Xamarin.Forms 2.3.231 and 2.3.5-pre3 and both did not demonstrate the issue. 

Can you attach a project that reproduces the issue so we can look into this further? When providing the requested information, please set the report status back to NEW otherwise we may close this report after 30 days of no response. Thanks!

[1] https://developer.xamarin.com/samples/xamarin-forms/UserInterface%5CListView%5CGrouping/
Comment 2 visu.avinash24 2017-05-20 07:39:40 UTC
In my case, problem was actually  with lambda expressions(not working in iOS real devices,but working in iOS simulator as well as in Android)
When I wrote using sql kind of grouping,it worked

	    //Using MVVM helpers by James Montemagno
		public ObservableRangeCollection<Grouping<string, EmployeeModel>> 
				GroupSchedule { get; } = new ObservableRangeCollection<Grouping<string, EmployeeModel>>();

				
	
		//Viewmodel here 
		{
			//your code goes here
		....................................
		
		
		//Not working using LINQ Lambda Expression
		  var groupedList = employees.GroupBy(e => e.JoinDate);
		
		//Working using sql kind of logic
		  var groupedList = (from e in employees
                               group e by e.JoinDate into tempGroup
                               select new Grouping<string, EmployeeModel>(tempGroup.Key, tempGroup)
                     ); 
				
		} 

		//XAML 
		<ListView   RefreshCommand="{Binding RefreshPageCommand}"
                    IsPullToRefreshEnabled="True"
                    IsRefreshing="{Binding IsBusy, Mode=OneWay}"
                    ItemSelected="OnItemSelected"
                    ItemsSource="{Binding GroupedList}"
                    SeparatorVisibility="None"
                    IsGroupingEnabled="True" 
                    HasUnevenRows = "True">

                    <ListView.GroupHeaderTemplate>
                        <DataTemplate>
                            <ViewCell Height="40">
                                <ViewCell.View>
                                    <StackLayout Padding="20,10,20,10" BackgroundColor="#f2f2f2">
                                        <Label Text="{Binding Key}"   />
                                    </StackLayout>
                                </ViewCell.View>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.GroupHeaderTemplate>
					
							</ListView>


I think binding the word "key" is not properly recognized when using lambda expression in iOS real devices
Comment 3 Jimmy [MSFT] 2017-06-05 21:15:34 UTC
Created attachment 22701 [details]
repro project

I was able to reproduce this using the modified ListView grouping sample I've attached.

This seems to be related to the Xamarin.iOS linker[1]. The linker is disabled for simulator builds which is why it works there. Device builds use "Link SDK assemblies only" as the default.

In this case, the linker might be stripping the System.Linq or another SDK assembly which is breaking the use of the lambda expression. However, I am not sure if this is expected in this case or if this still relates to Xamarin.Forms, but I will still confirm the report so that we may get another opinion.

In the meantime there are a couple "workarounds":

- Use the basic LINQ query instead as mentioned in the description
- Disable the linker for device builds. This is not recommended though as it will result in large app bundles.
- Tell the linker to skip the System.Linq assembly. In the iOS project options, go to iOS Build and enter the following as an additional mtouch argument:

-linkskip=System.Linq

[1] https://developer.xamarin.com/guides/ios/advanced_topics/linker/
Comment 4 Jimmy [MSFT] 2017-06-05 21:16:38 UTC
Marking as confirmed as mentioned in comment 3
Comment 5 Felipe Pessoto 2017-10-09 16:27:45 UTC
Hi Jimmy, any update on bug?

The first workaround, to use LINQ query syntax, didn't work, so I set the linkskip flag, but it increases the app size, in my case by 20MB
Comment 6 Joas 2017-10-10 11:13:46 UTC
The LINQ query syntax didn't work for me either. What did work for me was having a reference (C#, not XAML) to the IGrouping.Key property somewhere. Doesn't matter where, when of how many times.

-linkskip=System.Linq also works.
Comment 7 Felipe Pessoto 2017-10-16 15:57:39 UTC
Have you tested Custom Linker Config with XML? https://developer.xamarin.com/guides/cross-platform/advanced/custom_linking/
Comment 8 Joas 2017-10-17 11:36:42 UTC
A Customer Linker Configuration seems to work:
<linker>
	<assembly fullname="System.Core">
		<type fullname="IGrouping*">
			<method name="get_Key" />
		</type>
	</assembly>
</linker>
I've specifiek IGrouping*, because "IGrouping" doesn't seen to work and I don't know how to specify the generic types.
Comment 9 suzain lian 2017-12-11 07:08:28 UTC
back in school I refused to share homework or check solutions with my fellow chinese classmates, alternatively i might give an explanation for standards for them or percentage lab facts. If someone thinks that blatant plagiarism is a few kind of herbal law, then they are the wrong kind of buddies. i would say it's less complicated to hold your self easy inside the West as buddies with ethics are relative less complicated to find than in China and peer stress is lower.
http://www.assignmentninja.co.uk/assignment-writing-service