From: Stephane Delcroix Date: Fri, 27 Jan 2017 09:16:51 +0000 (+0100) Subject: [UWP] connect the actual ObservableCollection to the ComboBox.ItemsSource X-Git-Tag: beta-2.3.4-pre4~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f304d2bd9b5e92ffb6f0ac74bb6ce79395c5c9b5;p=platform%2Fupstream%2Fxamarin-forms.git [UWP] connect the actual ObservableCollection to the ComboBox.ItemsSource --- diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla51642.xaml b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla51642.xaml new file mode 100644 index 0000000..e7318b6 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla51642.xaml @@ -0,0 +1,17 @@ + + + + + + + 1 + 2 + 3 + + + + + + \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla51642.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla51642.xaml.cs new file mode 100644 index 0000000..ab16428 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla51642.xaml.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Xamarin.Forms; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 51642, "Delayed BindablePicker UWP", PlatformAffected.All)] + public partial class Bugzilla51642 : ContentPage + { + public Bugzilla51642 () + { + InitializeComponent (); + LoadDelayedVM(); + } + + public async void LoadDelayedVM() + { + await Task.Delay(1000); + Device.BeginInvokeOnMainThread(() => BindingContext = new Bz51642VM()); + } + } + + class Bz51642VM + { + public IList Items { + get { + return new List { "Foo", "Bar", "Baz" }; + } + } + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 75a376b..8d90656 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -156,6 +156,10 @@ + + Bugzilla51642.xaml + Code + @@ -625,4 +629,10 @@ MSBuild:UpdateDesignTimeXaml + + + Designer + MSBuild:UpdateDesignTimeXaml + + \ No newline at end of file diff --git a/Xamarin.Forms.Core/Picker.cs b/Xamarin.Forms.Core/Picker.cs index 56dc4d1..ae17969 100644 --- a/Xamarin.Forms.Core/Picker.cs +++ b/Xamarin.Forms.Core/Picker.cs @@ -1,7 +1,10 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Collections.Specialized; +using System.ComponentModel; +using System.Runtime.CompilerServices; using Xamarin.Forms.Platform; namespace Xamarin.Forms @@ -217,23 +220,29 @@ namespace Xamarin.Forms return _platformConfigurationRegistry.Value.On(); } - class LockableObservableListWrapper : INotifyCollectionChanged, IList + internal class LockableObservableListWrapper : IList, ICollection, INotifyCollectionChanged, INotifyPropertyChanged, IReadOnlyList, IReadOnlyCollection, IEnumerable, IEnumerable { - readonly ObservableList _list = new ObservableList(); + internal readonly ObservableCollection _list = new ObservableCollection(); - public bool IsLocked { get; set; } + event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged + { + add { ((INotifyCollectionChanged)_list).CollectionChanged += value; } + remove { ((INotifyCollectionChanged)_list).CollectionChanged -= value; } + } - event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged { - add { _list.CollectionChanged += value; } - remove { _list.CollectionChanged -= value; } + event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged { + add { ((INotifyPropertyChanged)_list).PropertyChanged += value; } + remove { ((INotifyPropertyChanged)_list).PropertyChanged -= value; } } + public bool IsLocked { get; set; } + void ThrowOnLocked() { if (IsLocked) throw new InvalidOperationException("The Items list can not be manipulated if the ItemsSource property is set"); - } + public string this [int index] { get { return _list [index]; } set { diff --git a/Xamarin.Forms.Platform.WinRT/PickerRenderer.cs b/Xamarin.Forms.Platform.WinRT/PickerRenderer.cs index 7095333..432b1d4 100644 --- a/Xamarin.Forms.Platform.WinRT/PickerRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/PickerRenderer.cs @@ -53,7 +53,7 @@ namespace Xamarin.Forms.Platform.WinRT Control.Loaded += ControlOnLoaded; } - Control.ItemsSource = Element.Items; + Control.ItemsSource = ((Picker.LockableObservableListWrapper)Element.Items)._list; UpdateTitle(); UpdateSelectedIndex();