diff options
author | Paul DiPietro <pauldipietro@users.noreply.github.com> | 2017-03-20 10:48:28 -0500 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2017-03-20 08:48:28 -0700 |
commit | 04d034057c9743712d826c290bf9b1f2a0dd7924 (patch) | |
tree | cffc1f68e2c54185940df469d12724ca1c87b406 | |
parent | 5ca7259959022253c6a71c5290854929291caec5 (diff) | |
download | xamarin-forms-04d034057c9743712d826c290bf9b1f2a0dd7924.tar.gz xamarin-forms-04d034057c9743712d826c290bf9b1f2a0dd7924.tar.bz2 xamarin-forms-04d034057c9743712d826c290bf9b1f2a0dd7924.zip |
[WinRT/UWP] Open Picker dropdown when calling Focus (#762)
3 files changed, 58 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla52266.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla52266.cs new file mode 100644 index 00000000..ab95f98f --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla52266.cs @@ -0,0 +1,38 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 52266, "[WinRT/UWP] Picker.Focus() does not open the dropdown", PlatformAffected.WinRT)] + public class Bugzilla52266 : TestContentPage + { + protected override void Init() + { + var picker = new Picker + { + ItemsSource = new string[] { "A", "B", "C" } + }; + Content = new StackLayout + { + Children = + { + picker, + new Button + { + Text = "Click to focus the picker", + Command = new Command(() => + { + picker.Focus(); + }) + } + } + }; + } + } +}
\ No newline at end of file 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 841b44ab..23fc5381 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 @@ -184,6 +184,7 @@ <DependentUpon>Bugzilla51642.xaml</DependentUpon> <SubType>Code</SubType> </Compile> + <Compile Include="$(MSBuildThisFileDirectory)Bugzilla52266.cs" /> <Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla34727.cs" /> diff --git a/Xamarin.Forms.Platform.WinRT/PickerRenderer.cs b/Xamarin.Forms.Platform.WinRT/PickerRenderer.cs index a7aa16f0..d4ee918e 100644 --- a/Xamarin.Forms.Platform.WinRT/PickerRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/PickerRenderer.cs @@ -19,6 +19,7 @@ namespace Xamarin.Forms.Platform.WinRT { bool _isAnimating; Brush _defaultBrush; + bool _dropDownWasOpened; protected override void Dispose(bool disposing) { @@ -32,6 +33,7 @@ namespace Xamarin.Forms.Platform.WinRT Control.DropDownClosed -= OnDropDownOpenStateChanged; Control.OpenAnimationCompleted -= ControlOnOpenAnimationCompleted; Control.Loaded -= ControlOnLoaded; + Control.GotFocus -= ControlOnGotFocus; } } @@ -51,6 +53,7 @@ namespace Xamarin.Forms.Platform.WinRT Control.OpenAnimationCompleted += ControlOnOpenAnimationCompleted; Control.ClosedAnimationStarted += ControlOnClosedAnimationStarted; Control.Loaded += ControlOnLoaded; + Control.GotFocus += ControlOnGotFocus; } Control.ItemsSource = ((LockableObservableListWrapper)Element.Items)._list; @@ -102,6 +105,19 @@ namespace Xamarin.Forms.Platform.WinRT } } + void ControlOnGotFocus(object sender, RoutedEventArgs routedEventArgs) + { + // The FormsComboBox is separate from the Popup/dropdown that it uses to select an item, + // and the behavior here is changed to be similar to the other platforms where focusing the + // Picker opens the dropdown (with the exception where if focus was given via keyboard, such + // as tabbing through controls). The _dropDownWasOpened flag is reset to false in the case that + // the FormsComboBox regained focus after the dropdown closed. + if (!_dropDownWasOpened && Control.FocusState != FocusState.Keyboard) + Control.IsDropDownOpen = true; + else + _dropDownWasOpened = false; + } + void OnControlSelectionChanged(object sender, SelectionChangedEventArgs e) { if (Element != null) @@ -129,6 +145,9 @@ namespace Xamarin.Forms.Platform.WinRT _isAnimating = false; // and force the final redraw ((IVisualElementController)Element)?.InvalidateMeasure(InvalidationTrigger.MeasureChanged); + + // Related to ControlOnGotFocus, _dropDownWasOpened is set to true + _dropDownWasOpened = true; } } |