diff options
author | Samantha Houts <samantha@teamredwall.com> | 2016-07-18 16:33:41 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-07-18 16:33:41 -0700 |
commit | a490740a2e76b9c53735d9778d4c6e0fa9e4bf22 (patch) | |
tree | 58c90dbb2c378412ceed70679eac6c33045954b9 /Xamarin.Forms.Platform.UAP | |
parent | be9f626c37949cc56c5f6901dac93093f3016fbf (diff) | |
download | xamarin-forms-a490740a2e76b9c53735d9778d4c6e0fa9e4bf22.tar.gz xamarin-forms-a490740a2e76b9c53735d9778d4c6e0fa9e4bf22.tar.bz2 xamarin-forms-a490740a2e76b9c53735d9778d4c6e0fa9e4bf22.zip |
[Win] Setting TabbedPage.BarTextColor works (#244)
[Win] TabbedPage BarBG takes precedence
Diffstat (limited to 'Xamarin.Forms.Platform.UAP')
-rw-r--r-- | Xamarin.Forms.Platform.UAP/Resources.xaml | 6 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs | 73 |
2 files changed, 61 insertions, 18 deletions
diff --git a/Xamarin.Forms.Platform.UAP/Resources.xaml b/Xamarin.Forms.Platform.UAP/Resources.xaml index 7a11fe4f..5df785f0 100644 --- a/Xamarin.Forms.Platform.UAP/Resources.xaml +++ b/Xamarin.Forms.Platform.UAP/Resources.xaml @@ -463,7 +463,7 @@ <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> @@ -473,7 +473,7 @@ <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> @@ -618,7 +618,7 @@ <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> diff --git a/Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs b/Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs index 0e6ce0b4..aa988b80 100644 --- a/Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs @@ -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; |