summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT.Tablet
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-07-18 16:33:41 -0700
committerJason Smith <jason.smith@xamarin.com>2016-07-18 16:33:41 -0700
commita490740a2e76b9c53735d9778d4c6e0fa9e4bf22 (patch)
tree58c90dbb2c378412ceed70679eac6c33045954b9 /Xamarin.Forms.Platform.WinRT.Tablet
parentbe9f626c37949cc56c5f6901dac93093f3016fbf (diff)
downloadxamarin-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.WinRT.Tablet')
-rw-r--r--Xamarin.Forms.Platform.WinRT.Tablet/TabbedPageRenderer.cs70
-rw-r--r--Xamarin.Forms.Platform.WinRT.Tablet/TabletResources.xaml4
2 files changed, 62 insertions, 12 deletions
diff --git a/Xamarin.Forms.Platform.WinRT.Tablet/TabbedPageRenderer.cs b/Xamarin.Forms.Platform.WinRT.Tablet/TabbedPageRenderer.cs
index bcdbe56d..7d3b1a8c 100644
--- a/Xamarin.Forms.Platform.WinRT.Tablet/TabbedPageRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT.Tablet/TabbedPageRenderer.cs
@@ -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();
diff --git a/Xamarin.Forms.Platform.WinRT.Tablet/TabletResources.xaml b/Xamarin.Forms.Platform.WinRT.Tablet/TabletResources.xaml
index cfd51257..9dad373a 100644
--- a/Xamarin.Forms.Platform.WinRT.Tablet/TabletResources.xaml
+++ b/Xamarin.Forms.Platform.WinRT.Tablet/TabletResources.xaml
@@ -250,7 +250,7 @@
<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>
@@ -261,7 +261,7 @@
<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>