diff options
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT')
5 files changed, 95 insertions, 27 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/NavigationPageRenderer.cs b/Xamarin.Forms.Platform.WinRT/NavigationPageRenderer.cs index df0c023d..30a74877 100644 --- a/Xamarin.Forms.Platform.WinRT/NavigationPageRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/NavigationPageRenderer.cs @@ -13,6 +13,8 @@ using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media.Animation; using Xamarin.Forms.Internals; +using Xamarin.Forms.PlatformConfiguration.WindowsSpecific; + #if WINDOWS_UWP using Windows.UI.Xaml.Data; using Windows.UI.Core; @@ -72,7 +74,7 @@ namespace Xamarin.Forms.Platform.WinRT { set { - _container.NavigationBarBackground = value; + _container.ToolbarBackground = value; UpdateTitleOnParents(); } } @@ -97,7 +99,7 @@ namespace Xamarin.Forms.Platform.WinRT return; _showTitle = value; - UpdateNavigationBarVisible(); + UpdateTitleVisible(); UpdateTitleOnParents(); } } @@ -187,6 +189,7 @@ namespace Xamarin.Forms.Platform.WinRT LookupRelevantParents(); UpdateTitleColor(); UpdateNavigationBarBackground(); + UpdateToolbarPlacement(); Element.PropertyChanged += OnElementPropertyChanged; ((INavigationPageController)Element).PushRequested += OnPushRequested; ((INavigationPageController)Element).PopRequested += OnPopRequested; @@ -258,6 +261,7 @@ namespace Xamarin.Forms.Platform.WinRT return Element.BarTextColor.ToBrush(); } + // TODO EZH Why don't this and GetToolBarProvider ever get called on either platform? Task<CommandBar> GetCommandBarAsync() { var platform = (Platform)Element.Platform; @@ -332,7 +336,7 @@ namespace Xamarin.Forms.Platform.WinRT else if (e.PropertyName == NavigationPage.BackButtonTitleProperty.PropertyName) UpdateBackButtonTitle(); else if (e.PropertyName == NavigationPage.HasNavigationBarProperty.PropertyName) - UpdateNavigationBarVisible(); + UpdateTitleVisible(); } void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) @@ -343,6 +347,8 @@ namespace Xamarin.Forms.Platform.WinRT UpdateNavigationBarBackground(); else if (e.PropertyName == Page.PaddingProperty.PropertyName) UpdatePadding(); + else if (e.PropertyName == PlatformConfiguration.WindowsSpecific.Page.ToolbarPlacementProperty.PropertyName) + UpdateToolbarPlacement(); } void OnLoaded(object sender, RoutedEventArgs args) @@ -434,7 +440,7 @@ namespace Xamarin.Forms.Platform.WinRT IVisualElementRenderer renderer = page.GetOrCreateRenderer(); - UpdateNavigationBarVisible(); + UpdateTitleVisible(); UpdateTitleOnParents(); if (isAnimated && _transition == null) @@ -484,16 +490,16 @@ namespace Xamarin.Forms.Platform.WinRT (this as ITitleProvider).BarBackgroundBrush = GetBarBackgroundBrush(); } - void UpdateNavigationBarVisible() + void UpdateTitleVisible() { UpdateTitleOnParents(); - bool showing = _container.ShowNavigationBar; - bool newValue = GetIsNavBarPossible() && NavigationPage.GetHasNavigationBar(_currentPage); + bool showing = _container.TitleVisibility == Visibility.Visible; + bool newValue = GetIsNavBarPossible() && NavigationPage.GetHasNavigationBar(_currentPage) && !string.IsNullOrEmpty(_currentPage.Title); if (showing == newValue) return; - _container.ShowNavigationBar = newValue; + _container.TitleVisibility = newValue ? Visibility.Visible : Visibility.Collapsed; // Force ContentHeight/Width to update, doesn't work from inside PageControl for some reason _container.UpdateLayout(); @@ -510,6 +516,18 @@ namespace Xamarin.Forms.Platform.WinRT (this as ITitleProvider).BarForegroundBrush = GetBarForegroundBrush(); } + void UpdateToolbarPlacement() + { +#if WINDOWS_UWP + if (_container == null) + { + return; + } + + _container.ToolbarPlacement = Element.OnThisPlatform().GetToolbarPlacement(); +#endif + } + #pragma warning disable 1998 // considered for removal async void UpdateTitleOnParents() #pragma warning restore 1998 diff --git a/Xamarin.Forms.Platform.WinRT/PageControl.xaml.cs b/Xamarin.Forms.Platform.WinRT/PageControl.xaml.cs index 0991db42..7be51c05 100644 --- a/Xamarin.Forms.Platform.WinRT/PageControl.xaml.cs +++ b/Xamarin.Forms.Platform.WinRT/PageControl.xaml.cs @@ -1,7 +1,10 @@ -using System.Threading.Tasks; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; +using Xamarin.Forms.PlatformConfiguration.WindowsSpecific; #if WINDOWS_UWP @@ -11,7 +14,7 @@ namespace Xamarin.Forms.Platform.UWP namespace Xamarin.Forms.Platform.WinRT #endif { - public sealed partial class PageControl : IToolbarProvider + public sealed partial class PageControl : IToolbarProvider { public static readonly DependencyProperty InvisibleBackButtonCollapsedProperty = DependencyProperty.Register("InvisibleBackButtonCollapsed", typeof(bool), typeof(PageControl), new PropertyMetadata(true, OnInvisibleBackButtonCollapsedChanged)); @@ -19,9 +22,9 @@ namespace Xamarin.Forms.Platform.WinRT public static readonly DependencyProperty ShowBackButtonProperty = DependencyProperty.Register("ShowBackButton", typeof(bool), typeof(PageControl), new PropertyMetadata(false, OnShowBackButtonChanged)); - public static readonly DependencyProperty ShowNavigationBarProperty = DependencyProperty.Register("ShowNavigationBar", typeof(bool), typeof(PageControl), new PropertyMetadata(true)); + public static readonly DependencyProperty TitleVisibilityProperty = DependencyProperty.Register(nameof(TitleVisibility), typeof(Visibility), typeof(PageControl), new PropertyMetadata(Visibility.Visible)); - public static readonly DependencyProperty NavigationBarBackgroundProperty = DependencyProperty.Register("NavigationBarBackground", typeof(Brush), typeof(PageControl), + public static readonly DependencyProperty ToolbarBackgroundProperty = DependencyProperty.Register(nameof(ToolbarBackground), typeof(Brush), typeof(PageControl), new PropertyMetadata(default(Brush))); public static readonly DependencyProperty BackButtonTitleProperty = DependencyProperty.Register("BackButtonTitle", typeof(string), typeof(PageControl), new PropertyMetadata(false)); @@ -36,10 +39,17 @@ namespace Xamarin.Forms.Platform.WinRT AppBarButton _backButton; CommandBar _commandBar; - TaskCompletionSource<CommandBar> _commandBarTcs; +#if WINDOWS_UWP + ToolbarPlacement _toolbarPlacement; + Border _bottomCommandBarArea; + Border _topCommandBarArea; +#endif + + TaskCompletionSource<CommandBar> _commandBarTcs; Windows.UI.Xaml.Controls.ContentPresenter _presenter; + - public PageControl() + public PageControl() { InitializeComponent(); } @@ -72,22 +82,34 @@ namespace Xamarin.Forms.Platform.WinRT set { SetValue(InvisibleBackButtonCollapsedProperty, value); } } - public Brush NavigationBarBackground + public Brush ToolbarBackground { - get { return (Brush)GetValue(NavigationBarBackgroundProperty); } - set { SetValue(NavigationBarBackgroundProperty, value); } + get { return (Brush)GetValue(ToolbarBackgroundProperty); } + set { SetValue(ToolbarBackgroundProperty, value); } } +#if WINDOWS_UWP + public ToolbarPlacement ToolbarPlacement + { + get { return _toolbarPlacement; } + set + { + _toolbarPlacement = value; + UpdateToolbarPlacement(); + } + } +#endif + public bool ShowBackButton { get { return (bool)GetValue(ShowBackButtonProperty); } set { SetValue(ShowBackButtonProperty, value); } } - public bool ShowNavigationBar + public Visibility TitleVisibility { - get { return (bool)GetValue(ShowNavigationBarProperty); } - set { SetValue(ShowNavigationBarProperty, value); } + get { return (Visibility)GetValue(TitleVisibilityProperty); } + set { SetValue(TitleVisibilityProperty, value); } } public Brush TitleBrush @@ -125,12 +147,14 @@ namespace Xamarin.Forms.Platform.WinRT _presenter = GetTemplateChild("presenter") as Windows.UI.Xaml.Controls.ContentPresenter; _commandBar = GetTemplateChild("CommandBar") as CommandBar; +#if WINDOWS_UWP + _bottomCommandBarArea = GetTemplateChild("BottomCommandBarArea") as Border; + _topCommandBarArea = GetTemplateChild("TopCommandBarArea") as Border; + UpdateToolbarPlacement(); +#endif TaskCompletionSource<CommandBar> tcs = _commandBarTcs; - if (tcs != null) - { - tcs.SetResult(_commandBar); - } + tcs?.SetResult(_commandBar); } void OnBackClicked(object sender, RoutedEventArgs e) @@ -162,5 +186,12 @@ namespace Xamarin.Forms.Platform.WinRT _backButton.Opacity = ShowBackButton ? 1 : 0; } - } + +#if WINDOWS_UWP + void UpdateToolbarPlacement() + { + ToolbarPlacementHelper.UpdateToolbarPlacement(_commandBar, ToolbarPlacement, _bottomCommandBarArea, _topCommandBarArea); + } +#endif + } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT/Platform.cs b/Xamarin.Forms.Platform.WinRT/Platform.cs index e780d95a..c16c896b 100644 --- a/Xamarin.Forms.Platform.WinRT/Platform.cs +++ b/Xamarin.Forms.Platform.WinRT/Platform.cs @@ -506,8 +506,8 @@ namespace Xamarin.Forms.Platform.WinRT return _page.BottomAppBar as CommandBar; #else IToolbarProvider provider = GetToolbarProvider(); - var titleProvider = provider as ITitleProvider; - if (provider == null || (titleProvider != null && !titleProvider.ShowTitle)) + //var titleProvider = provider as ITitleProvider; + if (provider == null) // || (titleProvider != null && !titleProvider.ShowTitle)) return null; return await provider.GetCommandBarAsync(); @@ -521,6 +521,7 @@ namespace Xamarin.Forms.Platform.WinRT _page.BottomAppBar = commandBar; return commandBar; #else + var bar = new FormsCommandBar(); if (Device.Idiom != TargetIdiom.Phone) bar.Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["TitleToolbar"]; diff --git a/Xamarin.Forms.Platform.WinRT/PlatformConfigurationExtensions.cs b/Xamarin.Forms.Platform.WinRT/PlatformConfigurationExtensions.cs new file mode 100644 index 00000000..f488c3c2 --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT/PlatformConfigurationExtensions.cs @@ -0,0 +1,17 @@ +#if WINDOWS_UWP + +namespace Xamarin.Forms.Platform.UWP +#else + +namespace Xamarin.Forms.Platform.WinRT +#endif +{ + public static class PlatformConfigurationExtensions + { + public static IPlatformElementConfiguration<PlatformConfiguration.Windows, T> OnThisPlatform<T>(this T element) + where T : Element, IElementConfiguration<T> + { + return (element).On<PlatformConfiguration.Windows>(); + } + } +} diff --git a/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj b/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj index 400737d0..fd73aae0 100644 --- a/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj +++ b/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj @@ -66,6 +66,7 @@ <Compile Include="..\Xamarin.Forms.Core\Properties\GlobalAssemblyInfo.cs"> <Link>Properties\GlobalAssemblyInfo.cs</Link> </Compile> + <Compile Include="PlatformConfigurationExtensions.cs" /> </ItemGroup> <ItemGroup Condition=" '$(OS)' != 'Unix' "> <Compile Include="BrushHelpers.cs" /> |