diff options
author | E.Z. Hart <hartez@users.noreply.github.com> | 2017-01-27 17:14:21 -0700 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2017-01-28 00:14:20 +0000 |
commit | 11331bc10e854c06c45cb9a6f860fcde2b71667f (patch) | |
tree | 21fc9b7bf9e21ef7b2147b43fb80c07faad08133 /Xamarin.Forms.Platform.UAP/NavigationPageRendererUWP.cs | |
parent | 1d3e7cf380a8a3a6949bd3f97f0d5ac41ae2d19d (diff) | |
download | xamarin-forms-11331bc10e854c06c45cb9a6f860fcde2b71667f.tar.gz xamarin-forms-11331bc10e854c06c45cb9a6f860fcde2b71667f.tar.bz2 xamarin-forms-11331bc10e854c06c45cb9a6f860fcde2b71667f.zip |
Make WinRT/UWP platform classes more maintainable (#652)
* Split Platform.cs into partial classes
* Split the NavigationPageRenderer into partial classes for easier maintenance
* Simplify GetCommandBarAsync, remove unneeded comments
* Correct broken GetCommandBarAsync method
* Fix OSX build
Diffstat (limited to 'Xamarin.Forms.Platform.UAP/NavigationPageRendererUWP.cs')
-rw-r--r-- | Xamarin.Forms.Platform.UAP/NavigationPageRendererUWP.cs | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.UAP/NavigationPageRendererUWP.cs b/Xamarin.Forms.Platform.UAP/NavigationPageRendererUWP.cs new file mode 100644 index 00000000..a56ce903 --- /dev/null +++ b/Xamarin.Forms.Platform.UAP/NavigationPageRendererUWP.cs @@ -0,0 +1,97 @@ +using Windows.UI.Core; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Data; +using Xamarin.Forms.PlatformConfiguration.WindowsSpecific; + +namespace Xamarin.Forms.Platform.UWP +{ + public partial class NavigationPageRenderer : IToolBarForegroundBinder + { + SystemNavigationManager _navManager; + + public void BindForegroundColor(AppBar appBar) + { + SetAppBarForegroundBinding(appBar); + } + + public void BindForegroundColor(AppBarButton button) + { + SetAppBarForegroundBinding(button); + } + + void SetAppBarForegroundBinding(FrameworkElement element) + { + element.SetBinding(Control.ForegroundProperty, + new Windows.UI.Xaml.Data.Binding { Path = new PropertyPath("TitleBrush"), Source = _container, RelativeSource = new RelativeSource { Mode = RelativeSourceMode.TemplatedParent } }); + } + + void UpdateToolbarPlacement() + { + if (_container == null) + { + return; + } + + _container.ToolbarPlacement = Element.OnThisPlatform().GetToolbarPlacement(); + } + + void UpdateShowTitle() + { + ((ITitleProvider)this).ShowTitle = _parentTabbedPage == null && _parentMasterDetailPage == null; + } + + static object GetDefaultColor() + { + return Windows.UI.Xaml.Application.Current.Resources["SystemControlBackgroundChromeMediumLowBrush"]; + } + + void UpdateBackButton() + { + bool showBackButton = PageController.InternalChildren.Count > 1 && NavigationPage.GetHasBackButton(_currentPage); + _container.ShowBackButton = showBackButton; + + if (_navManager != null) + { + _navManager.AppViewBackButtonVisibility = showBackButton ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; + } + } + + async void UpdateTitleOnParents() + { + if (Element == null) + return; + + ITitleProvider render = null; + if (_parentTabbedPage != null) + { + render = Platform.GetRenderer(_parentTabbedPage) as ITitleProvider; + if (render != null) + render.ShowTitle = (_parentTabbedPage.CurrentPage == Element) && NavigationPage.GetHasNavigationBar(_currentPage); + } + + if (_parentMasterDetailPage != null) + { + render = Platform.GetRenderer(_parentMasterDetailPage) as ITitleProvider; + if (render != null) + render.ShowTitle = (_parentMasterDetailPage.Detail == Element) && NavigationPage.GetHasNavigationBar(_currentPage); + } + + if (render != null && render.ShowTitle) + { + render.Title = _currentPage.Title; + render.BarBackgroundBrush = GetBarBackgroundBrush(); + render.BarForegroundBrush = GetBarForegroundBrush(); + } + + if (_showTitle || (render != null && render.ShowTitle)) + { + var platform = Element.Platform as Platform; + if (platform != null) + { + await platform.UpdateToolbarItems(); + } + } + } + } +} |