From 17fdde66d94155fc62a034fa6658995bef6fd6e5 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Tue, 22 Mar 2016 13:02:25 -0700 Subject: Initial import --- Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs (limited to 'Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs') diff --git a/Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs b/Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs new file mode 100644 index 00000000..d829b787 --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs @@ -0,0 +1,65 @@ +using System.Threading.Tasks; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Media; + +#if WINDOWS_UWP + +namespace Xamarin.Forms.Platform.UWP +#else +namespace Xamarin.Forms.Platform.WinRT +#endif +{ + public class FormsPivot : Pivot, IToolbarProvider + { + public static readonly DependencyProperty ToolbarVisibilityProperty = DependencyProperty.Register("ToolbarVisibility", typeof(Visibility), typeof(FormsPivot), + new PropertyMetadata(Visibility.Collapsed)); + + public static readonly DependencyProperty ToolbarForegroundProperty = DependencyProperty.Register("ToolbarForeground", typeof(Brush), typeof(FormsPivot), new PropertyMetadata(default(Brush))); + + public static readonly DependencyProperty ToolbarBackgroundProperty = DependencyProperty.Register("ToolbarBackground", typeof(Brush), typeof(FormsPivot), new PropertyMetadata(default(Brush))); + + CommandBar _commandBar; + + TaskCompletionSource _commandBarTcs; + + public Brush ToolbarBackground + { + get { return (Brush)GetValue(ToolbarBackgroundProperty); } + set { SetValue(ToolbarBackgroundProperty, value); } + } + + public Brush ToolbarForeground + { + get { return (Brush)GetValue(ToolbarForegroundProperty); } + set { SetValue(ToolbarForegroundProperty, value); } + } + + public Visibility ToolbarVisibility + { + get { return (Visibility)GetValue(ToolbarVisibilityProperty); } + set { SetValue(ToolbarVisibilityProperty, value); } + } + + Task IToolbarProvider.GetCommandBarAsync() + { + if (_commandBar != null) + return Task.FromResult(_commandBar); + + _commandBarTcs = new TaskCompletionSource(); + ApplyTemplate(); + return _commandBarTcs.Task; + } + + protected override void OnApplyTemplate() + { + base.OnApplyTemplate(); + _commandBar = GetTemplateChild("CommandBar") as CommandBar; + TaskCompletionSource tcs = _commandBarTcs; + if (tcs != null) + { + tcs.SetResult(_commandBar); + } + } + } +} \ No newline at end of file -- cgit v1.2.3