diff options
author | Samantha Houts <samantha@teamredwall.com> | 2016-04-18 09:46:51 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-04-18 09:46:51 -0700 |
commit | 75f112400223ea628ee008d311b7d5d54d98eafe (patch) | |
tree | af859c326a488cb0801fd57fca7bbce0cf0b4ad0 /Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs | |
parent | fc05a57e9dfa5b70e21b08f9c8f839b7986b4698 (diff) | |
download | xamarin-forms-75f112400223ea628ee008d311b7d5d54d98eafe.tar.gz xamarin-forms-75f112400223ea628ee008d311b7d5d54d98eafe.tar.bz2 xamarin-forms-75f112400223ea628ee008d311b7d5d54d98eafe.zip |
BarBackgroundColor and BarTextColor on TabbedPage (#96)
* [Core] Add properties to TabbedPage
* [Controls] Add properties to test page
* [iOS] Added BarBackgroundColor & BarTextColor to TabbedPage
* [A] Added BarBackgroundColor & BarTextColor to TabbedPage
* [UWP] Added BarBackgroundColor & BarTextColor to TabbedPage
* [WinRT] Format file
* [WinRT] Added BarBackgroundColor & BarTextColor to TabbedPage
* [Docs] Updated docs
Diffstat (limited to 'Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs')
-rw-r--r-- | Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs b/Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs index 1f1e15fc..cde40717 100644 --- a/Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs @@ -15,7 +15,7 @@ namespace Xamarin.Forms.Platform.UWP { Loaded += TabbedPagePresenter_Loaded; Unloaded += TabbedPagePresenter_Unloaded; - SizeChanged += (s, e) => + SizeChanged += (s, e) => { if (ActualWidth > 0 && ActualHeight > 0) { @@ -44,7 +44,7 @@ namespace Xamarin.Forms.Platform.UWP bool _showTitle; VisualElementTracker<Page, Pivot> _tracker; - public Pivot Control { get; private set; } + public FormsPivot Control { get; private set; } public TabbedPage Element { get; private set; } @@ -157,7 +157,7 @@ namespace Xamarin.Forms.Platform.UWP { if (Control == null) { - Control = new FormsPivot { Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["TabbedPageStyle"] }; + Control = new FormsPivot { Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["TabbedPageStyle"], }; Control.SelectionChanged += OnSelectionChanged; @@ -170,6 +170,8 @@ namespace Xamarin.Forms.Platform.UWP Control.DataContext = Element; OnPagesChanged(Element.Children, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); UpdateCurrentPage(); + UpdateBarTextColor(); + UpdateBarBackgroundColor(); ((INotifyCollectionChanged)Element.Children).CollectionChanged += OnPagesChanged; element.PropertyChanged += OnElementPropertyChanged; @@ -178,6 +180,7 @@ namespace Xamarin.Forms.Platform.UWP Control.SetValue(AutomationProperties.AutomationIdProperty, element.AutomationId); } + OnElementChanged(new VisualElementChangedEventArgs(oldElement, element)); } @@ -201,8 +204,13 @@ namespace Xamarin.Forms.Platform.UWP void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { - if (e.PropertyName == "CurrentPage") + if (e.PropertyName == nameof(TabbedPage.CurrentPage)) UpdateCurrentPage(); + else if (e.PropertyName == TabbedPage.BarTextColorProperty.PropertyName) + UpdateBarTextColor(); + else if (e.PropertyName == TabbedPage.BarBackgroundColorProperty.PropertyName) + UpdateBarBackgroundColor(); + } void OnLoaded(object sender, RoutedEventArgs args) @@ -243,6 +251,32 @@ namespace Xamarin.Forms.Platform.UWP Element.SendDisappearing(); } + Brush GetBarBackgroundBrush() + { + object defaultColor = Windows.UI.Xaml.Application.Current.Resources["SystemControlBackgroundChromeMediumLowBrush"]; + if (Element.BarBackgroundColor.IsDefault && defaultColor != null) + return (Brush)defaultColor; + return Element.BarBackgroundColor.ToBrush(); + } + + Brush GetBarForegroundBrush() + { + object defaultColor = Windows.UI.Xaml.Application.Current.Resources["ApplicationForegroundThemeBrush"]; + if (Element.BarTextColor.IsDefault) + return (Brush)defaultColor; + return Element.BarTextColor.ToBrush(); + } + + void UpdateBarBackgroundColor() + { + Control.ToolbarBackground = GetBarBackgroundBrush(); + } + + void UpdateBarTextColor() + { + Control.ToolbarForeground = GetBarForegroundBrush(); + } + void UpdateBarVisibility() { (Control as FormsPivot).ToolbarVisibility = _showTitle ? Visibility.Visible : Visibility.Collapsed; @@ -255,6 +289,9 @@ namespace Xamarin.Forms.Platform.UWP var nav = page as NavigationPage; ((ITitleProvider)this).ShowTitle = nav != null; + UpdateBarTextColor(); + UpdateBarBackgroundColor(); + if (page == null) return; |