Bug 27050 - ListView ItemsSource binding is not updated when in a TabbedPage Child Page
Summary: ListView ItemsSource binding is not updated when in a TabbedPage Child Page
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.4.2
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Rui Marinho
URL:
Depends on:
Blocks:
 
Reported: 2015-02-13 11:08 UTC by John Miller [MSFT]
Modified: 2015-06-22 04:33 UTC (History)
8 users (show)

Tags: AC
Is this bug a regression?: ---
Last known good build:


Attachments
Test Case (353.48 KB, application/zip)
2015-02-13 11:08 UTC, John Miller [MSFT]
Details
Updated Test Case (71.78 KB, application/zip)
2015-04-08 13:53 UTC, Jimmy [MSFT]
Details
App Output and ADB Log (47.53 KB, application/zip)
2015-04-08 13:58 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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description John Miller [MSFT] 2015-02-13 11:08:57 UTC
Created attachment 9828 [details]
Test Case

**Overview:**

   ListView does not show the updated ItemsSource after a PropertyChanged event when it is in a child page of a TabbedPage.

**Steps to Reproduce:**

   1. Run the attached sample on an Android simulator.
   2. Press the Add Enabled button. <- This should update the ItemsSource and display.
   3. A new page was launched, press the Back button to return to the page. 
   4. Notice the list in Tab1 is empty (it should not be)
   5. Press the Tab2 to toggle tab pages
   6. Toggle back to Tab1 
   7. Now the content shows in the ListView, only after switching tabs.

**Actual Results:**

   ListView content is not visible until tab is switched

**Expected Results:**

   ListView content should be visible at step 4 above (without switching tabs first)

**Build Date & Platform:**

   Tests with XF 1.3.3 and 1.3.4-pre3

**Additional Information:**

   I removed the TabbedPage in Page1.xaml and replaced it with just a ContentPage. With this modification, the sample produces the expected results. It only seemed to have an issue when being in a TabbedPage.
Comment 1 Sadik Ali 2015-02-17 00:48:33 UTC
We have checked this issue and unable to reproduce this issue with the help of bug description.

We observed that when we tap on Add Enable move to the another page and when tapeed on back button ,Listview showing Enable in their list.

We have checked this issue on XAP device as well as android emulator but getting same behaviour.

Screencast: http://www.screencast.com/t/BRIiFFjDm

Please let me know if I missed anything to reproduce this issue.

Environment Info:
=== Xamarin Studio ===

Version 5.7 (build 661)
Installation UUID: 3d25a767-a003-4a7d-9f5e-e57987cf6cf0
Runtime:
	Mono 3.12.0 ((detached/de2f33f)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000076

=== Apple Developer Tools ===

Xcode 6.1 (6602)
Build 6A1052c

=== Xamarin.iOS ===

Version: 8.6.0.51 (Business Edition)
Hash: dfb682f
Branch: 
Build date: 2015-01-08 13:39:32-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (Business Edition)
Android SDK: /Users/mac360_xamarin/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin.Mac ===

Version: 1.10.0.18 (Business Edition)

=== Build Information ===

Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 16:31:31-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

=== Operating System ===

Mac OS X 10.10.0
Darwin mac360-xamarins-Mac-mini.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 2 Paul Diston 2015-03-10 05:01:09 UTC
This issue has been made worse when running on version 1.4.1.6342-pre1.

Although previously the items would appear only after switching tabs, the items now no longer appear at all.
Comment 3 Paul Diston 2015-03-10 05:07:39 UTC
This issue is also present in the latest stable version (1.4.0.6341).
Comment 4 Paul Diston 2015-04-08 07:04:52 UTC
This is still an issue in version 1.4.2.6353-pre2.
Comment 5 DavidWelsh 2015-04-08 08:19:21 UTC
OK I've downloaded the sample from John Miller above.  I noted that he wrote:

**Additional Information:**

   I removed the TabbedPage in Page1.xaml and replaced it with just a
ContentPage. With this modification, the sample produces the expected results.
It only seemed to have an issue when being in a TabbedPage.

So when I checked Sadik Ali's screencast, I noticed that he hadn't changed the first page to be a tabbed page and it was still set as content page (the working version).  Hence why the bug was not reproducible.

I've given it a try with the tabbed page on the main page (with 2 tab children) and the bug was present.  I then updated to 1.4.2.6353-pre2 and the bug has in fact worsened.  When jumping between the tabs to trigger the refresh, the item never appears.

Hope this is helpful.
Comment 6 Jimmy [MSFT] 2015-04-08 13:53:22 UTC
Created attachment 10679 [details]
Updated Test Case

I downloaded the test case attached and since John noted that he removed the TabbedPage from Page1.xaml, I re-added the TabbedPage and following the steps to reproduce I was able to reproduce the issue.

I also tested this with Forms 1.4.1 and 1.4.2-pre2. With Forms 1.4+, performing steps 5-7 from the steps to reproduce does not cause the item to appear in the ListView until a scrolling gesture is done on the ListView.

I have attached a new test case with the TabbedPage added to Page1.xaml and all other packages updated to their latest versions.


=== Updated Steps to Reproduce ===

   1. Run the attached sample on an Android simulator.
   2. Press the Add Enabled button. <- This should update the ItemsSource and
display.
   3. A new page was launched, press the Back button to return to the page. 
   4. Notice the list in "Page 1" is empty (it should not be)
   5. Press the "Page 2" to toggle tab pages
   6. Toggle back to "Page 1" 
   7. Perform a scrolling gesture on the ListView <- This will cause the item to appear


=== Environment Info === 
=== Xamarin Studio ===

Version 5.8.2 (build 7)
Installation UUID: 94ce5106-6a72-4691-b34e-cd5857b1db66
Runtime:
	Mono 3.12.1 ((detached/0849ec7)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312010003

=== Xamarin.Android ===

Version: 4.20.1.0 (Business Edition)
Android SDK: /Users/jimmygarrido/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 6.2 (6776)
Build 6C131e

=== Xamarin.iOS ===

Version: 8.8.2.4 (Business Edition)
Hash: 981acb3
Branch: 
Build date: 2015-03-25 14:21:05-0400

=== Xamarin.Mac ===

Version: 1.12.0.14 (Business Edition)

=== Build Information ===

Release ID: 508020007
Git revision: 067ed06873402cf780f8a0899bb332c2a1c0af22
Build date: 2015-03-27 14:17:13-04
Xamarin addins: 02510c4990dee3475c282b3182d588975a63ff07

=== Operating System ===

Mac OS X 10.10.2
Darwin Jimmys-MacBook-Pro.local 14.1.0 Darwin Kernel Version 14.1.0
    Mon Dec 22 23:10:38 PST 2014
    root:xnu-2782.10.72~2/RELEASE_X86_64 x86_64
Comment 7 Jimmy [MSFT] 2015-04-08 13:58:37 UTC
Created attachment 10680 [details]
App Output and ADB Log
Comment 8 Jimmy [MSFT] 2015-04-08 14:13:34 UTC
Marking as NEW since I have attached an updated test case that reproduces the issue.

(In reply to comment #6)
Comment 9 John Miller [MSFT] 2015-04-08 14:29:10 UTC
I was able to reproduce this with API 21 on a device using the project from comment #7.
Comment 10 Rui Marinho 2015-06-18 16:51:37 UTC
Hey guys this isn't a issue with Xamarin.Forms, what is happening is that the ItemsSource is binded to a List and not a ObservableCollection. Since List doesn't implement INotifyPropertyChange there's no way the ListiView to get notify of changes in the collection when you Add a new item. 

Just make this change your MyViewModel

>public MyViewModel()
>{
>	Items = new ObservableCollection<Item>();
>}

>public ObservableCollection<Item> Items { get; set; }
Comment 11 Paul Diston 2015-06-22 04:25:45 UTC
Hi,

Unfortunately, there are cases where you can not use an ObservableCollection, hence the use of the List in this test sample. One such example is when reading records from a Sqlite database. The property which the ItemsSource is bound to is of type List, the backing of this property is a read from the database, therefore you can use the NotifyPropertyChanged event to then trigger the read from the property and hence the ItemsSource will be updated.

The change should not be just to use an ObservableCollection as the use of a List property in addition to the NotifyPropertyChanged event is a valid use case.

Please can you review this issue again.

Thanks

Paul Diston
Comment 12 Rui Marinho 2015-06-22 04:33:30 UTC
Hi Paulo, sorry but this is not a issue, you can use a List<T> for your ItemsSource but there's no support for adding and removing items, if you are getting your data from a Sqlite, you should wrap that calls in a different way and wrap that list ins a ObservableCollection.

Take in mind this is how for example Microsoft xml/bindings also work.