diff --git a/.nuspec/Xamarin.Forms.nuspec b/.nuspec/Xamarin.Forms.nuspec index 44a90efc3..8d96dde7e 100644 --- a/.nuspec/Xamarin.Forms.nuspec +++ b/.nuspec/Xamarin.Forms.nuspec @@ -226,6 +226,7 @@ + diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue8177.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue8177.cs new file mode 100644 index 000000000..bc12a409a --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue8177.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +using System.Linq; +using System.Threading.Tasks; + + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +using Xamarin.Forms.Core.UITests; +#endif +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 8177, "[Bug] Picker does not update when it's underlying list changes content", + PlatformAffected.UWP)] +#if UITEST + [NUnit.Framework.Category(UITestCategories.Picker)] +#endif + public class Issue8177 : TestContentPage + { + protected override void Init() + { + var layout = new StackLayout(); + + var instructions = new Label { Text = "Open the Picker below. It should contain 3 items ('one', 'two', 'three'). Tap the button marked 'Change Picker Contents'. The Picker should now contain four items ('uno', 'dos', 'tres', 'quatro'). If it does not, the test has failed."}; + + var button = new Button { Text = "Change Picker Contents " }; + + var originalList = new List { "one", "two", "three" }; + var picker = new Picker { ItemsSource = originalList }; + + var newList = new List { "uno", "dos", "tres", "quatro" }; + button.Clicked += (sender, args) => { picker.ItemsSource = newList; }; + + layout.Children.Add(instructions); + layout.Children.Add(button); + layout.Children.Add(picker); + + Content = layout; + } + } +} 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 5822171d5..a38a000da 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 @@ -20,6 +20,7 @@ + @@ -1595,7 +1596,7 @@ Designer MSBuild:UpdateDesignTimeXaml - + Designer diff --git a/Xamarin.Forms.Platform.UAP/FormsComboBox.cs b/Xamarin.Forms.Platform.UAP/FormsComboBox.cs index 2d18f8b4b..5a66e99dd 100644 --- a/Xamarin.Forms.Platform.UAP/FormsComboBox.cs +++ b/Xamarin.Forms.Platform.UAP/FormsComboBox.cs @@ -1,5 +1,4 @@ using System; -using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media.Animation; using WVisualState = Windows.UI.Xaml.VisualState; @@ -14,10 +13,15 @@ namespace Xamarin.Forms.Platform.UWP internal bool IsOpeningAnimated { get; private set; } + public FormsComboBox() + { + DefaultStyleKey = typeof(FormsComboBox); + } + protected override void OnApplyTemplate() { base.OnApplyTemplate(); - + if (Device.Idiom == TargetIdiom.Phone) { // If we're running on the phone, we have to give the PickerRenderer hooks diff --git a/Xamarin.Forms.Platform.UAP/PickerRenderer.cs b/Xamarin.Forms.Platform.UAP/PickerRenderer.cs index 502cc8131..dacfcf19f 100644 --- a/Xamarin.Forms.Platform.UAP/PickerRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/PickerRenderer.cs @@ -1,12 +1,7 @@ using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; using System.ComponentModel; -using System.Linq; using System.Threading.Tasks; using Windows.UI.Core; -using Windows.UI.Text; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; @@ -20,7 +15,6 @@ namespace Xamarin.Forms.Platform.UWP bool _fontApplied; bool _isAnimating; Brush _defaultBrush; - FontFamily _defaultFontFamily; protected override void Dispose(bool disposing) { @@ -59,7 +53,7 @@ namespace Xamarin.Forms.Platform.UWP WireUpFormsVsm(); } - Control.ItemsSource = GetItems(Element.Items); + Control.ItemsSource = ((LockableObservableListWrapper)Element.Items)._list; UpdateTitle(); UpdateSelectedIndex(); UpdateCharacterSpacing(); @@ -91,7 +85,6 @@ namespace Xamarin.Forms.Platform.UWP // The defaults from the control template won't be available // right away; we have to wait until after the template has been applied _defaultBrush = Control.Foreground; - _defaultFontFamily = Control.FontFamily; UpdateFont(); UpdateTextColor(); } @@ -175,35 +168,6 @@ namespace Xamarin.Forms.Platform.UWP void UpdateCharacterSpacing() { Control.CharacterSpacing = Element.CharacterSpacing.ToEm(); - - if (Control.Header is TextBlock header) - { - header.CharacterSpacing = Element.CharacterSpacing.ToEm(); - } - - if (Control.SelectedValue is TextBlock item) - { - item.CharacterSpacing = Element.CharacterSpacing.ToEm(); - } - - if(Control.ItemsSource is ObservableCollection collection) - { - collection.ForEach(f=>f.CharacterSpacing = Control.CharacterSpacing); - } - } - - - TextBlock ConvertStrongToTextBlock(string text) - { - return new TextBlock{ - Text = text, - CharacterSpacing = Control.CharacterSpacing - }; - } - - ObservableCollection GetItems(IList items) - { - return new ObservableCollection(items.Select(ConvertStrongToTextBlock)); } void UpdateFont() @@ -252,21 +216,7 @@ namespace Xamarin.Forms.Platform.UWP void UpdateTitle() { - if (!Element.IsSet(Picker.TitleColorProperty)) - { - Control.HeaderTemplate = null; - Control.Header = new TextBlock - { - Text = Element.Title ?? string.Empty, - CharacterSpacing = Element.CharacterSpacing.ToEm(), - }; - } - else - { - Control.Header = null; - Control.HeaderTemplate = (Windows.UI.Xaml.DataTemplate)Windows.UI.Xaml.Application.Current.Resources["ComboBoxHeader"]; - Control.DataContext = Element; - } + Control.DataContext = Element; } } } \ No newline at end of file diff --git a/Xamarin.Forms.Platform.UAP/PickerStyle.xaml b/Xamarin.Forms.Platform.UAP/PickerStyle.xaml new file mode 100644 index 000000000..3b7787f6f --- /dev/null +++ b/Xamarin.Forms.Platform.UAP/PickerStyle.xaml @@ -0,0 +1,460 @@ + + + + + + + + + + + + + + + diff --git a/Xamarin.Forms.Platform.UAP/Resources.xaml b/Xamarin.Forms.Platform.UAP/Resources.xaml index 90b0a8dd7..198c60c91 100644 --- a/Xamarin.Forms.Platform.UAP/Resources.xaml +++ b/Xamarin.Forms.Platform.UAP/Resources.xaml @@ -16,6 +16,7 @@ + @@ -351,8 +352,4 @@ - - - - \ No newline at end of file diff --git a/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj b/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj index 0e16d97d9..5054cdf48 100644 --- a/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj +++ b/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj @@ -251,6 +251,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + MSBuild:Compile Designer