diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2017-01-27 10:16:51 +0100 |
---|---|---|
committer | Paul DiPietro <pauldipietro@users.noreply.github.com> | 2017-02-23 09:37:17 -0600 |
commit | 32431a4427f60693394256ff3088c9b156ca798e (patch) | |
tree | 6f196698b2ddebd6327c05ebef194daadbfd3917 | |
parent | e8a3cfd75585916881ccb3cae4eca511d0c1d467 (diff) | |
download | xamarin-forms-32431a4427f60693394256ff3088c9b156ca798e.tar.gz xamarin-forms-32431a4427f60693394256ff3088c9b156ca798e.tar.bz2 xamarin-forms-32431a4427f60693394256ff3088c9b156ca798e.zip |
[UWP] connect the actual ObservableCollection to the ComboBox.ItemsSource
5 files changed, 82 insertions, 8 deletions
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 00000000..e7318b6e --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla51642.xaml @@ -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 index 00000000..ab164287 --- /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<string> Items { + get { + return new List<String> { "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 1bb0a0c7..26f5bcbf 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 @@ -171,6 +171,10 @@ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla47923.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla48236.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla47971.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" /> @@ -648,4 +652,10 @@ <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 diff --git a/Xamarin.Forms.Core/Picker.cs b/Xamarin.Forms.Core/Picker.cs index 56dc4d1a..ae179696 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<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 { diff --git a/Xamarin.Forms.Platform.WinRT/PickerRenderer.cs b/Xamarin.Forms.Platform.WinRT/PickerRenderer.cs index 7095333a..432b1d4f 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(); |