summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT/FormsComboBox.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/FormsComboBox.cs')
-rw-r--r--Xamarin.Forms.Platform.WinRT/FormsComboBox.cs68
1 files changed, 68 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/FormsComboBox.cs b/Xamarin.Forms.Platform.WinRT/FormsComboBox.cs
new file mode 100644
index 00000000..f693c942
--- /dev/null
+++ b/Xamarin.Forms.Platform.WinRT/FormsComboBox.cs
@@ -0,0 +1,68 @@
+using System;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Media.Animation;
+
+#if WINDOWS_UWP
+
+namespace Xamarin.Forms.Platform.UWP
+#else
+
+namespace Xamarin.Forms.Platform.WinRT
+#endif
+{
+ public class FormsComboBox : ComboBox
+ {
+ internal bool IsClosingAnimated { get; private set; }
+
+ internal bool IsFullScreen => Device.Idiom == TargetIdiom.Phone && Items != null && Items.Count > 5;
+
+ internal bool IsOpeningAnimated { get; private set; }
+
+ 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
+ // into the opening and closing animations so it can handle them smoothly
+ // and measure at the appropriate times
+
+ var openedState = GetTemplateChild("Opened") as VisualState;
+ if (openedState != null)
+ {
+ openedState.Storyboard.Completed += (sender, o) => OnOpenAnimationCompleted();
+ IsOpeningAnimated = true;
+ }
+
+ var closedState = GetTemplateChild("Closed") as VisualState;
+
+ // On the phone, this is a dummy animation we've added to the closed state in the VSM
+ // Since it finishes immediately, we can use its Completed event to signal that the
+ // closing animation has started
+ var closedSignalAnimation = closedState?.Storyboard.Children[0] as DoubleAnimation;
+
+ if (closedSignalAnimation != null)
+ {
+ closedSignalAnimation.Completed += (sender, o) => OnClosedAnimationStarted();
+ IsClosingAnimated = true;
+ }
+ }
+ }
+
+ protected virtual void OnClosedAnimationStarted()
+ {
+ ClosedAnimationStarted?.Invoke(this, EventArgs.Empty);
+ }
+
+ protected virtual void OnOpenAnimationCompleted()
+ {
+ OpenAnimationCompleted?.Invoke(this, EventArgs.Empty);
+ }
+
+ internal event EventHandler<EventArgs> ClosedAnimationStarted;
+
+ internal event EventHandler<EventArgs> OpenAnimationCompleted;
+ }
+} \ No newline at end of file