summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.UAP/NavigationPageRendererUWP.cs
blob: 978695cfe4004a421bb5a2e2f17334d9c866285e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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 = Element.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();
				}
			}
		}
	}
}