[UWP] connect the actual ObservableCollection to the ComboBox.ItemsSource
authorStephane Delcroix <stephane@delcroix.org>
Fri, 27 Jan 2017 09:16:51 +0000 (10:16 +0100)
committerRui Marinho <me@ruimarinho.net>
Fri, 10 Mar 2017 14:33:26 +0000 (14:33 +0000)
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla51642.xaml [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla51642.xaml.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Core/Picker.cs
Xamarin.Forms.Platform.WinRT/PickerRenderer.cs

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 (file)
index 0000000..e7318b6
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
+             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+             x:Class="Xamarin.Forms.Controls.Issues.Bugzilla51642">
+  <StackLayout>
+    
+  <Picker>
+    <Picker.Items>
+      <x:String>1</x:String>
+      <x:String>2</x:String>
+      <x:String>3</x:String>
+    </Picker.Items>
+  </Picker>
+    <Picker ItemsSource="{Binding Items}"/>
+
+  </StackLayout>
+</ContentPage>
\ 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 (file)
index 0000000..ab16428
--- /dev/null
@@ -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<string> Items {
+            get {
+                return new List<String> { "Foo", "Bar", "Baz" };
+            }
+        }
+    }
+}
index 75a376b..8d90656 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla48236.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla47971.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla51238.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Bugzilla51642.xaml.cs">
+      <DependentUpon>Bugzilla51642.xaml</DependentUpon>
+      <SubType>Code</SubType>
+    </Compile>
     <Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla34727.cs" />
       <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
     </EmbeddedResource>
   </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla51642.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+  </ItemGroup>
 </Project>
\ No newline at end of file
index 56dc4d1..ae17969 100644 (file)
@@ -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<T>();
                }
 
-               class LockableObservableListWrapper : INotifyCollectionChanged, IList<string>
+               internal class LockableObservableListWrapper : IList<string>, ICollection<string>, INotifyCollectionChanged, INotifyPropertyChanged, IReadOnlyList<string>, IReadOnlyCollection<string>, IEnumerable<string>, IEnumerable
                {
-                       readonly ObservableList<string> _list = new ObservableList<string>();
+                       internal readonly ObservableCollection<string> _list = new ObservableCollection<string>();
 
-                       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 {
index 7095333..432b1d4 100644 (file)
@@ -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();