summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT.Phone
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.Phone
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.Phone')
-rw-r--r--Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs6
-rw-r--r--Xamarin.Forms.Platform.WinRT.Phone/PhoneResources.xaml6
-rw-r--r--Xamarin.Forms.Platform.WinRT.Phone/TabbedPageRenderer.cs103
3 files changed, 77 insertions, 38 deletions
diff --git a/Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs b/Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs
index d829b787..a2e765b3 100644
--- a/Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs
+++ b/Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs
@@ -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;
diff --git a/Xamarin.Forms.Platform.WinRT.Phone/PhoneResources.xaml b/Xamarin.Forms.Platform.WinRT.Phone/PhoneResources.xaml
index 4dcf4be5..b693a226 100644
--- a/Xamarin.Forms.Platform.WinRT.Phone/PhoneResources.xaml
+++ b/Xamarin.Forms.Platform.WinRT.Phone/PhoneResources.xaml
@@ -242,7 +242,7 @@
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
- <TextBlock Text="{Binding Title}" Foreground="{TemplateBinding ToolbarForeground}" />
+ <TextBlock Text="{Binding Title}" Name="TabbedPageHeaderTextBlock" />
</DataTemplate>
</Setter.Value>
</Setter>
@@ -452,10 +452,6 @@
<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">
diff --git a/Xamarin.Forms.Platform.WinRT.Phone/TabbedPageRenderer.cs b/Xamarin.Forms.Platform.WinRT.Phone/TabbedPageRenderer.cs
index 68cafae3..df4fba71 100644
--- a/Xamarin.Forms.Platform.WinRT.Phone/TabbedPageRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT.Phone/TabbedPageRenderer.cs
@@ -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