[Win] Setting TabbedPage.BarTextColor works (#244)
authorSamantha Houts <samantha@teamredwall.com>
Mon, 18 Jul 2016 23:33:41 +0000 (16:33 -0700)
committerJason Smith <jason.smith@xamarin.com>
Mon, 18 Jul 2016 23:33:41 +0000 (16:33 -0700)
[Win] TabbedPage BarBG takes precedence

Xamarin.Forms.Controls/CoreGallery.cs
Xamarin.Forms.Platform.UAP/Resources.xaml
Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs
Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs
Xamarin.Forms.Platform.WinRT.Phone/PhoneResources.xaml
Xamarin.Forms.Platform.WinRT.Phone/TabbedPageRenderer.cs
Xamarin.Forms.Platform.WinRT.Tablet/TabbedPageRenderer.cs
Xamarin.Forms.Platform.WinRT.Tablet/TabletResources.xaml
Xamarin.Forms.Platform.WinRT/FrameworkElementExtensions.cs

index 8fd1f7b..dc3217c 100644 (file)
@@ -117,7 +117,8 @@ namespace Xamarin.Forms.Controls
                                {
                                        Title = "Rubriques",
                                        Icon = "coffee.png",
-                                       BarBackgroundColor = Color.Blue
+                                       BarBackgroundColor = Color.Blue,
+                                       BarTextColor = Color.Aqua
                                });
 
                        Children.Add(new NavigationPage(new Page())
index 7a11fe4..5df785f 100644 (file)
         <uwp:EntryCellTextBox IsEnabled="{Binding IsEnabled}" Header="{Binding}" Text="{Binding Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextAlignment="{Binding HorizontalTextAlignment,Converter={StaticResource HorizontalTextAlignmentConverter}}" PlaceholderText="{Binding Placeholder}"  InputScope="{Binding Keyboard,Converter={StaticResource KeyboardConverter}}" HorizontalAlignment="Stretch">
                        <uwp:EntryCellTextBox.HeaderTemplate>
                                <DataTemplate>
-                                       <TextBlock Text="{Binding Label}" Style="{ThemeResource BaseTextBlockStyle}" Foreground="{Binding LabelColor, Converter={StaticResource ColorConverter}, ConverterParameter=DefaultTextForegroundThemeBrush}" />
+                                       <TextBlock Text="{Binding Label}" Style="{ThemeResource BaseTextBlockStyle}" Foreground="{Binding LabelColor, Converter={StaticResource ColorConverter}, ConverterParameter=SystemControlBackgroundChromeMediumLowBrush}" />
                                </DataTemplate>
                        </uwp:EntryCellTextBox.HeaderTemplate>
                </uwp:EntryCellTextBox>
                <Setter Property="HeaderTemplate">
                        <Setter.Value>
                                <DataTemplate>
-                                       <TextBlock Text="{Binding Title}" Foreground="{Binding ToolbarForeground}" Style="{ThemeResource BodyTextBlockStyle}" />
+                                       <TextBlock Name="TabbedPageHeaderTextBlock" Text="{Binding Title}" Style="{ThemeResource BodyTextBlockStyle}" />
                                </DataTemplate>
                        </Setter.Value>
                </Setter>
                                             <ContentControl.Clip>
                                                 <RectangleGeometry x:Name="HeaderClipperGeometry"/>
                                             </ContentControl.Clip>
-                                            <Grid Background="{TemplateBinding ToolbarBackground}">
+                                                                                       <Grid Name="TabbedPageHeaderGrid" Background="{TemplateBinding ToolbarBackground}">
                                                 <PivotHeaderPanel x:Name="StaticHeader" Visibility="Collapsed"/>
                                                 <PivotHeaderPanel x:Name="Header">
                                                     <PivotHeaderPanel.RenderTransform>
index 0e6ce0b..aa988b8 100644 (file)
@@ -7,6 +7,7 @@ using Windows.UI.Xaml.Automation;
 using Windows.UI.Xaml.Controls;
 using Windows.UI.Xaml.Media;
 using Xamarin.Forms.Internals;
+using WGrid = Windows.UI.Xaml.Controls.Grid;
 
 namespace Xamarin.Forms.Platform.UWP
 {
@@ -16,7 +17,7 @@ namespace Xamarin.Forms.Platform.UWP
                {
                        Loaded += TabbedPagePresenter_Loaded;
                        Unloaded += TabbedPagePresenter_Unloaded;
-                       SizeChanged += (s, e) => 
+                       SizeChanged += (s, e) =>
                        {
                                if (ActualWidth > 0 && ActualHeight > 0)
                                {
@@ -41,10 +42,17 @@ namespace Xamarin.Forms.Platform.UWP
 
        public class TabbedPageRenderer : IVisualElementRenderer, ITitleProvider, IToolbarProvider
        {
+               const string TabBarHeaderTextBlockName = "TabbedPageHeaderTextBlock";
+               const string TabBarHeaderGridName = "TabbedPageHeaderGrid";
+
+               Color _barBackgroundColor;
+               Color _barTextColor;
                bool _disposed;
                bool _showTitle;
                VisualElementTracker<Page, Pivot> _tracker;
 
+               ITitleProvider TitleProvider => this;
+
                public FormsPivot Control { get; private set; }
 
                public TabbedPage Element { get; private set; }
@@ -71,12 +79,12 @@ namespace Xamarin.Forms.Platform.UWP
 
                Brush ITitleProvider.BarBackgroundBrush
                {
-                       set { (Control as FormsPivot).ToolbarBackground = value; }
+                       set { Control.ToolbarBackground = value; }
                }
 
                Brush ITitleProvider.BarForegroundBrush
                {
-                       set { (Control as FormsPivot).ToolbarForeground = value; }
+                       set { Control.ToolbarForeground = value; }
                }
 
                IPageController PageController => Element as IPageController;
@@ -172,9 +180,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;
@@ -183,7 +190,6 @@ namespace Xamarin.Forms.Platform.UWP
                                        Control.SetValue(AutomationProperties.AutomationIdProperty, element.AutomationId);
                        }
 
-
                        OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));
                }
 
@@ -208,17 +214,22 @@ namespace Xamarin.Forms.Platform.UWP
                void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
                {
                        if (e.PropertyName == nameof(TabbedPage.CurrentPage))
+                       {
                                UpdateCurrentPage();
+                               UpdateBarTextColor();
+                               UpdateBarBackgroundColor();
+                       }
                        else if (e.PropertyName == TabbedPage.BarTextColorProperty.PropertyName)
                                UpdateBarTextColor();
                        else if (e.PropertyName == TabbedPage.BarBackgroundColorProperty.PropertyName)
                                UpdateBarBackgroundColor();
-
                }
 
                void OnLoaded(object sender, RoutedEventArgs args)
                {
                        PageController?.SendAppearing();
+                       UpdateBarTextColor();
+                       UpdateBarBackgroundColor();
                }
 
                void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
@@ -259,24 +270,59 @@ namespace Xamarin.Forms.Platform.UWP
                Brush GetBarForegroundBrush()
                {
                        object defaultColor = Windows.UI.Xaml.Application.Current.Resources["ApplicationForegroundThemeBrush"];
-                       if (Element.BarTextColor.IsDefault)
+                       if (Element.BarTextColor.IsDefault && defaultColor != null)
                                return (Brush)defaultColor;
                        return Element.BarTextColor.ToBrush();
                }
 
                void UpdateBarBackgroundColor()
                {
-                       Control.ToolbarBackground = GetBarBackgroundBrush();
+                       if (Element == null) return;
+                       var barBackgroundColor = Element.BarBackgroundColor;
+
+                       if (barBackgroundColor == _barBackgroundColor) return;
+                       _barBackgroundColor = barBackgroundColor;
+
+                       var controlToolbarBackground = Control.ToolbarBackground;
+                       if (controlToolbarBackground == null && barBackgroundColor.IsDefault) return;
+
+                       var brush = GetBarBackgroundBrush();
+                       if (brush == controlToolbarBackground) return;
+
+                       TitleProvider.BarBackgroundBrush = brush;
+
+                       foreach (WGrid tabBarGrid in Control.GetDescendantsByName<WGrid>(TabBarHeaderGridName))
+                       {
+                               tabBarGrid.Background = brush;
+                       }
                }
 
                void UpdateBarTextColor()
                {
-                       Control.ToolbarForeground = GetBarForegroundBrush();
+                       if (Element == null) return;
+                       var barTextColor = Element.BarTextColor;
+
+                       if (barTextColor == _barTextColor) return;
+                       _barTextColor = barTextColor;
+
+                       var controlToolbarForeground = Control.ToolbarForeground;
+                       if (controlToolbarForeground == null && barTextColor.IsDefault) return;
+
+                       var brush = GetBarForegroundBrush();
+                       if (brush == controlToolbarForeground)
+                               return;
+
+                       TitleProvider.BarForegroundBrush = brush;
+
+                       foreach (TextBlock tabBarTextBlock in Control.GetDescendantsByName<TextBlock>(TabBarHeaderTextBlockName))
+                       {
+                               tabBarTextBlock.Foreground = brush;
+                       }
                }
 
                void UpdateBarVisibility()
                {
-                       (Control as FormsPivot).ToolbarVisibility = _showTitle ? Visibility.Visible : Visibility.Collapsed;
+                       Control.ToolbarVisibility = _showTitle ? Visibility.Visible : Visibility.Collapsed;
                }
 
                void UpdateCurrentPage()
@@ -284,10 +330,7 @@ namespace Xamarin.Forms.Platform.UWP
                        Page page = Element.CurrentPage;
 
                        var nav = page as NavigationPage;
-                       ((ITitleProvider)this).ShowTitle = nav != null;
-
-                       UpdateBarTextColor();
-                       UpdateBarBackgroundColor();
+                       TitleProvider.ShowTitle = nav != null;
 
                        if (page == null)
                                return;
index d829b78..a2e765b 100644 (file)
@@ -12,12 +12,12 @@ namespace Xamarin.Forms.Platform.WinRT
 {
        public class FormsPivot : Pivot, IToolbarProvider
        {
-               public static readonly DependencyProperty ToolbarVisibilityProperty = DependencyProperty.Register("ToolbarVisibility", typeof(Visibility), typeof(FormsPivot),
+               public static readonly DependencyProperty ToolbarVisibilityProperty = DependencyProperty.Register(nameof(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 ToolbarForegroundProperty = DependencyProperty.Register(nameof(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)));
+               public static readonly DependencyProperty ToolbarBackgroundProperty = DependencyProperty.Register(nameof(ToolbarBackground), typeof(Brush), typeof(FormsPivot), new PropertyMetadata(default(Brush)));
 
                CommandBar _commandBar;
 
index 4dcf4be..b693a22 100644 (file)
         <Setter Property="HeaderTemplate">
             <Setter.Value>
                 <DataTemplate>
-                    <TextBlock Text="{Binding Title}" Foreground="{TemplateBinding ToolbarForeground}" />
+                                       <TextBlock Text="{Binding Title}" Name="TabbedPageHeaderTextBlock" />
                 </DataTemplate>
             </Setter.Value>
         </Setter>
                <local:TabbedPagePresenter Content="{Binding Converter={StaticResource PageToRenderer}}" />
        </DataTemplate>
 
-       <DataTemplate x:Key="TabbedPageHeader">
-               <TextBlock Text="{Binding Title}" />
-       </DataTemplate>
-
        <Style x:Key="JumpListGrid" TargetType="GridView">
                <Setter Property="Background" Value="#80000000" />
                <Setter Property="ItemTemplate">
index 68cafae..df4fba7 100644 (file)
@@ -6,6 +6,7 @@ using Windows.UI.Xaml.Automation;
 using Windows.UI.Xaml.Controls;
 using Windows.UI.Xaml.Media;
 using Xamarin.Forms.Internals;
+using WGrid = Windows.UI.Xaml.Controls.Grid;
 
 namespace Xamarin.Forms.Platform.WinRT
 {
@@ -13,7 +14,8 @@ namespace Xamarin.Forms.Platform.WinRT
        {
                public TabbedPagePresenter()
                {
-                       SizeChanged += (s, e) => {
+                       SizeChanged += (s, e) =>
+                       {
                                if (ActualWidth > 0 && ActualHeight > 0)
                                {
                                        var tab = ((Page)DataContext);
@@ -26,6 +28,18 @@ namespace Xamarin.Forms.Platform.WinRT
        public class TabbedPageRenderer
                : IVisualElementRenderer, ITitleProvider
        {
+               const string TabBarHeaderTextBlockName = "TabbedPageHeaderTextBlock";
+               const string TabBarHeaderGridName = "TabbedPageHeaderGrid";
+
+               Color _barBackgroundColor;
+               Color _barTextColor;
+               bool _disposed;
+               VisualElementTracker<Page, Pivot> _tracker;
+               bool _showTitle;
+
+               ITitleProvider TitleProvider => this;
+               IPageController PageController => Element as IPageController;
+
                public event EventHandler<VisualElementChangedEventArgs> ElementChanged;
 
                public FrameworkElement ContainerElement
@@ -68,15 +82,16 @@ namespace Xamarin.Forms.Platform.WinRT
                        {
                                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"],
+                                               ItemTemplate = (Windows.UI.Xaml.DataTemplate)Windows.UI.Xaml.Application.Current.Resources["TabbedPage"]
                                        };
-                                       Control.HeaderTemplate = (Windows.UI.Xaml.DataTemplate)Windows.UI.Xaml.Application.Current.Resources["TabbedPageHeader"];
-                                       Control.ItemTemplate = (Windows.UI.Xaml.DataTemplate)Windows.UI.Xaml.Application.Current.Resources["TabbedPage"];
 
                                        Control.SelectionChanged += OnSelectionChanged;
 
-                                       Tracker = new BackgroundTracker<Pivot>(Windows.UI.Xaml.Controls.Control.BackgroundProperty) {
+                                       Tracker = new BackgroundTracker<Pivot>(Windows.UI.Xaml.Controls.Control.BackgroundProperty)
+                                       {
                                                Element = (Page)element,
                                                Control = Control,
                                                Container = Control
@@ -88,9 +103,8 @@ namespace Xamarin.Forms.Platform.WinRT
 
                                Control.DataContext = Element;
                                OnPagesChanged(Element.Children, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
+
                                UpdateCurrentPage();
-                               UpdateBarTextColor();
-                               UpdateBarBackgroundColor();
 
                                ((INotifyCollectionChanged)Element.Children).CollectionChanged += OnPagesChanged;
                                element.PropertyChanged += OnElementPropertyChanged;
@@ -173,7 +187,7 @@ namespace Xamarin.Forms.Platform.WinRT
                                        return;
                                _showTitle = value;
 
-                               (Control as FormsPivot).ToolbarVisibility = _showTitle ? Visibility.Visible : Visibility.Collapsed;
+                               Control.ToolbarVisibility = _showTitle ? Visibility.Visible : Visibility.Collapsed;
                        }
                }
 
@@ -195,7 +209,7 @@ namespace Xamarin.Forms.Platform.WinRT
                {
                        set
                        {
-                               (Control as FormsPivot).ToolbarBackground = value;
+                               Control.ToolbarBackground = value;
                        }
                }
 
@@ -203,7 +217,7 @@ namespace Xamarin.Forms.Platform.WinRT
                {
                        set
                        {
-                               (Control as FormsPivot).ToolbarForeground = value;
+                               Control.ToolbarForeground = value;
                        }
                }
 
@@ -214,10 +228,6 @@ namespace Xamarin.Forms.Platform.WinRT
                                changed(this, e);
                }
 
-               bool _disposed;
-               VisualElementTracker<Page, Pivot> _tracker;
-               bool _showTitle;
-
                void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
                {
                        e.Apply(Element.Children, Control.Items);
@@ -238,7 +248,11 @@ namespace Xamarin.Forms.Platform.WinRT
                void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
                {
                        if (e.PropertyName == nameof(TabbedPage.CurrentPage))
+                       {
                                UpdateCurrentPage();
+                               UpdateBarTextColor();
+                               UpdateBarBackgroundColor();
+                       }
                        else if (e.PropertyName == TabbedPage.BarTextColorProperty.PropertyName)
                                UpdateBarTextColor();
                        else if (e.PropertyName == TabbedPage.BarBackgroundColorProperty.PropertyName)
@@ -257,18 +271,14 @@ namespace Xamarin.Forms.Platform.WinRT
 
                void OnLoaded(object sender, RoutedEventArgs args)
                {
-                       if (Element == null)
-                               return;
-
-                       ((IPageController)Element).SendAppearing();
+                       PageController?.SendAppearing();
+                       UpdateBarTextColor();
+                       UpdateBarBackgroundColor();
                }
 
                void OnUnloaded(object sender, RoutedEventArgs args)
                {
-                       if (Element == null)
-                               return;
-
-                       ((IPageController)Element).SendDisappearing();
+                       PageController?.SendDisappearing();
                }
 
                void OnTrackerUpdated(object sender, EventArgs e)
@@ -287,19 +297,53 @@ namespace Xamarin.Forms.Platform.WinRT
                Brush GetBarForegroundBrush()
                {
                        object defaultColor = Windows.UI.Xaml.Application.Current.Resources["AppBarItemForegroundThemeBrush"];
-                       if (Element.BarTextColor.IsDefault)
+                       if (Element.BarTextColor.IsDefault && defaultColor != null)
                                return (Brush)defaultColor;
                        return Element.BarTextColor.ToBrush();
                }
 
                void UpdateBarBackgroundColor()
                {
-                       Control.ToolbarBackground = GetBarBackgroundBrush();
+                       if (Element == null) return;
+                       var barBackgroundColor = Element.BarBackgroundColor;
+
+                       if (barBackgroundColor == _barBackgroundColor) return;
+                       _barBackgroundColor = barBackgroundColor;
+
+                       var controlToolbarBackground = Control.ToolbarBackground;
+                       if (controlToolbarBackground == null && barBackgroundColor.IsDefault) return;
+
+                       var brush = GetBarBackgroundBrush();
+                       if (brush == controlToolbarBackground) return;
+
+                       TitleProvider.BarBackgroundBrush = brush;
+
+                       foreach (WGrid tabBarGrid in Control.GetDescendantsByName<WGrid>(TabBarHeaderGridName))
+                       {
+                               tabBarGrid.Background = brush;
+                       }
                }
 
                void UpdateBarTextColor()
                {
-                       Control.ToolbarForeground = GetBarForegroundBrush();
+                       if (Element == null) return;
+                       var barTextColor = Element.BarTextColor;
+
+                       if (barTextColor == _barTextColor) return;
+                       _barTextColor = barTextColor;
+
+                       var controlToolbarForeground = Control.ToolbarForeground;
+                       if (controlToolbarForeground == null && barTextColor.IsDefault) return;
+
+                       var brush = GetBarForegroundBrush();
+                       if (brush == controlToolbarForeground) return;
+
+                       TitleProvider.BarForegroundBrush = brush;
+
+                       foreach (TextBlock tabBarTextBlock in Control.GetDescendantsByName<TextBlock>(TabBarHeaderTextBlockName))
+                       {
+                               tabBarTextBlock.Foreground = brush;
+                       }
                }
 
                void UpdateTitle(Page child)
@@ -314,11 +358,10 @@ namespace Xamarin.Forms.Platform.WinRT
                        {
                                Control.Title = navigationRenderer.Title;
                        }
-                       else {
-                               ((ITitleProvider)this).ShowTitle = false;
+                       else
+                       {
+                               TitleProvider.ShowTitle = false;
                        }
-
                }
-
        }
 }
\ No newline at end of file
index bcdbe56..7d3b1a8 100644 (file)
@@ -12,8 +12,12 @@ namespace Xamarin.Forms.Platform.WinRT
        public class TabbedPageRenderer
                : IVisualElementRenderer
        {
-               Canvas _canvas;
+               const string TabBarHeaderTextBlockName = "TabbedPageHeaderTextBlock";
+               const string TabbedPageHeaderStackPanelName = "TabbedPageHeaderStackPanel";
 
+               Color _barBackgroundColor;
+               Color _barTextColor;
+               Canvas _canvas;
                bool _disposed;
                TabsControl _tabs;
                VisualElementTracker<Page, Canvas> _tracker;
@@ -83,16 +87,16 @@ namespace Xamarin.Forms.Platform.WinRT
                                                Container = _canvas
                                        };
 
-                                       _canvas.Loaded += OnLoaded;
-                                       _canvas.Unloaded += OnUnloaded;
+                                       _canvas.Loaded += canvas_OnLoaded;
+                                       _canvas.Unloaded += canvas_OnUnloaded;
+
+                                       _tabs.Loaded += tabs_OnLoaded;
                                }
 
                                _tabs.DataContext = element;
 
                                OnPagesChanged(Page.Children, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
                                UpdateCurrentPage();
-                               UpdateBarTextColor();
-                               UpdateBarBackgroundColor();
 
                                ((INotifyCollectionChanged)Page.Children).CollectionChanged += OnPagesChanged;
                                element.PropertyChanged += OnElementPropertyChanged;
@@ -112,7 +116,7 @@ namespace Xamarin.Forms.Platform.WinRT
                Brush GetBarForegroundBrush()
                {
                        object defaultColor = Windows.UI.Xaml.Application.Current.Resources["ApplicationForegroundThemeBrush"];
-                       if (Page.BarTextColor.IsDefault)
+                       if (Page.BarTextColor.IsDefault && defaultColor != null)
                                return (Brush)defaultColor;
                        return Page.BarTextColor.ToBrush();
                }
@@ -176,7 +180,11 @@ namespace Xamarin.Forms.Platform.WinRT
                void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
                {
                        if (e.PropertyName == nameof(TabbedPage.CurrentPage))
+                       {
                                UpdateCurrentPage();
+                               UpdateBarTextColor();
+                               UpdateBarBackgroundColor();
+                       }
                        else if (e.PropertyName == TabbedPage.BarTextColorProperty.PropertyName)
                                UpdateBarTextColor();
                        else if (e.PropertyName == TabbedPage.BarBackgroundColorProperty.PropertyName)
@@ -185,12 +193,48 @@ namespace Xamarin.Forms.Platform.WinRT
 
                void UpdateBarBackgroundColor()
                {
-                       _tabs.Background = GetBarBackgroundBrush();
+                       TabbedPage tabbedPage = Element as TabbedPage;
+                       if (tabbedPage == null) return;
+                       var barBackgroundColor = tabbedPage.BarBackgroundColor;
+
+                       if (barBackgroundColor == _barBackgroundColor) return;
+                       _barBackgroundColor = barBackgroundColor;
+
+                       var controlToolbarBackground = _tabs.ToolbarBackground;
+                       if (controlToolbarBackground == null && barBackgroundColor.IsDefault) return;
+
+                       var brush = GetBarBackgroundBrush();
+                       if (brush == controlToolbarBackground) return;
+
+                       _tabs.ToolbarBackground = brush;
+
+                       foreach (StackPanel tabBarGrid in _tabs.GetDescendantsByName<StackPanel>(TabbedPageHeaderStackPanelName))
+                       {
+                               tabBarGrid.Background = brush;
+                       }
                }
 
                void UpdateBarTextColor()
                {
-                       _tabs.Foreground = GetBarForegroundBrush();
+                       TabbedPage tabbedPage = Element as TabbedPage;
+                       if (tabbedPage == null) return;
+                       var barTextColor = tabbedPage.BarTextColor;
+
+                       if (barTextColor == _barTextColor) return;
+                       _barTextColor = barTextColor;
+
+                       var controlToolbarForeground = _tabs.ToolbarForeground;
+                       if (controlToolbarForeground == null && barTextColor.IsDefault) return;
+
+                       var brush = GetBarForegroundBrush();
+                       if (brush == controlToolbarForeground) return;
+
+                       _tabs.ToolbarForeground = brush;
+
+                       foreach (TextBlock tabBarTextBlock in _tabs.GetDescendantsByName<TextBlock>(TabBarHeaderTextBlockName))
+                       {
+                               tabBarTextBlock.Foreground = brush;
+                       }
                }
 
                void UpdateCurrentPage()
@@ -202,7 +246,7 @@ namespace Xamarin.Forms.Platform.WinRT
                                _canvas.Children.Add(renderer.ContainerElement);
                }
 
-               void OnLoaded(object sender, RoutedEventArgs args)
+               void canvas_OnLoaded(object sender, RoutedEventArgs args)
                {
                        if (Page == null)
                                return;
@@ -211,6 +255,12 @@ namespace Xamarin.Forms.Platform.WinRT
                        PageController.SendAppearing();
                }
 
+               void tabs_OnLoaded(object sender, RoutedEventArgs e)
+               {
+                       UpdateBarTextColor();
+                       UpdateBarBackgroundColor();
+               }
+
                Windows.UI.Xaml.Controls.Page GetTopPage()
                {
                        var frame = Window.Current.Content as Windows.UI.Xaml.Controls.Frame;
@@ -262,7 +312,7 @@ namespace Xamarin.Forms.Platform.WinRT
                        page.TopAppBar = null;
                }
 
-               void OnUnloaded(object sender, RoutedEventArgs args)
+               void canvas_OnUnloaded(object sender, RoutedEventArgs args)
                {
                        RemoveTabs();
                        PageController?.SendDisappearing();
index cfd5125..9dad373 100644 (file)
                <Setter Property="ItemsPanel">
                        <Setter.Value>
                                <ItemsPanelTemplate>
-                                       <StackPanel Orientation="Horizontal" Margin="0,11,0,0" Background="{TemplateBinding ToolbarBackground}" />
+                                       <StackPanel Orientation="Horizontal" Margin="0,11,0,0" Background="{Binding BarBackgroundColor, Converter={StaticResource ColorConverter}, ConverterParameter=TabButtonBackgroundBrush}" Name="TabbedPageHeaderStackPanel" />
                                </ItemsPanelTemplate>
                        </Setter.Value>
                </Setter>
                                                <StackPanel VerticalAlignment="Bottom">
                                                        <Image DataContext="{Binding Icon, Converter={StaticResource ImageConverter}}" Source="{Binding Value}" HorizontalAlignment="Left" />
                                                        <TextBlock Margin="0,15,0,15" Text="{Binding Title, Converter={StaticResource UpperConverter}}"
-                                                                          Style="{ThemeResource CaptionTextBlockStyle}" FontWeight="SemiBold" Foreground="{TemplateBinding ToolbarForeground}"  HorizontalAlignment="Left" />
+                                                                          Style="{ThemeResource CaptionTextBlockStyle}" FontWeight="SemiBold" Name="TabbedPageHeaderTextBlock"  HorizontalAlignment="Left" />
                                                </StackPanel>
                                        </local:TabButton>
                                </DataTemplate>
index 64b2daa..eb040e0 100644 (file)
@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 using System.Linq;
 using System.Reflection;
 using Windows.UI.Xaml;
@@ -71,6 +72,23 @@ namespace Xamarin.Forms.Platform.WinRT
                        element.SetBinding(GetForegroundProperty(element), binding);
                }
 
+               internal static IEnumerable<T> GetDescendantsByName<T>(this DependencyObject parent, string elementName) where T : DependencyObject
+               {
+                       int myChildrenCount = VisualTreeHelper.GetChildrenCount(parent);
+                       for (int i = 0; i < myChildrenCount; i++)
+                       {
+                               var child = VisualTreeHelper.GetChild(parent, i);
+                               var controlName = child.GetValue(FrameworkElement.NameProperty) as string;
+                               if (controlName == elementName && child is T)
+                                       yield return child as T;
+                               else
+                               {
+                                       foreach (var subChild in child.GetDescendantsByName<T>(elementName))
+                                               yield return subChild;
+                               }
+                       }
+               }
+
                internal static T GetFirstDescendant<T>(this DependencyObject element) where T : FrameworkElement
                {
                        int count = VisualTreeHelper.GetChildrenCount(element);