{
Title = "Rubriques",
Icon = "coffee.png",
- BarBackgroundColor = Color.Blue
+ BarBackgroundColor = Color.Blue,
+ BarTextColor = Color.Aqua
});
Children.Add(new NavigationPage(new Page())
<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>
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
{
{
Loaded += TabbedPagePresenter_Loaded;
Unloaded += TabbedPagePresenter_Unloaded;
- SizeChanged += (s, e) =>
+ SizeChanged += (s, e) =>
{
if (ActualWidth > 0 && ActualHeight > 0)
{
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; }
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;
Control.DataContext = Element;
OnPagesChanged(Element.Children, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
+
UpdateCurrentPage();
- UpdateBarTextColor();
- UpdateBarBackgroundColor();
((INotifyCollectionChanged)Element.Children).CollectionChanged += OnPagesChanged;
element.PropertyChanged += OnElementPropertyChanged;
Control.SetValue(AutomationProperties.AutomationIdProperty, element.AutomationId);
}
-
OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));
}
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)
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()
Page page = Element.CurrentPage;
var nav = page as NavigationPage;
- ((ITitleProvider)this).ShowTitle = nav != null;
-
- UpdateBarTextColor();
- UpdateBarBackgroundColor();
+ TitleProvider.ShowTitle = nav != null;
if (page == null)
return;
{
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;
<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">
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
{
{
public TabbedPagePresenter()
{
- SizeChanged += (s, e) => {
+ SizeChanged += (s, e) =>
+ {
if (ActualWidth > 0 && ActualHeight > 0)
{
var tab = ((Page)DataContext);
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
{
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
Control.DataContext = Element;
OnPagesChanged(Element.Children, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
+
UpdateCurrentPage();
- UpdateBarTextColor();
- UpdateBarBackgroundColor();
((INotifyCollectionChanged)Element.Children).CollectionChanged += OnPagesChanged;
element.PropertyChanged += OnElementPropertyChanged;
return;
_showTitle = value;
- (Control as FormsPivot).ToolbarVisibility = _showTitle ? Visibility.Visible : Visibility.Collapsed;
+ Control.ToolbarVisibility = _showTitle ? Visibility.Visible : Visibility.Collapsed;
}
}
{
set
{
- (Control as FormsPivot).ToolbarBackground = value;
+ Control.ToolbarBackground = value;
}
}
{
set
{
- (Control as FormsPivot).ToolbarForeground = value;
+ Control.ToolbarForeground = value;
}
}
changed(this, e);
}
- bool _disposed;
- VisualElementTracker<Page, Pivot> _tracker;
- bool _showTitle;
-
void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
{
e.Apply(Element.Children, Control.Items);
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)
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)
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)
{
Control.Title = navigationRenderer.Title;
}
- else {
- ((ITitleProvider)this).ShowTitle = false;
+ else
+ {
+ TitleProvider.ShowTitle = false;
}
-
}
-
}
}
\ No newline at end of file
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;
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;
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();
}
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)
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()
_canvas.Children.Add(renderer.ContainerElement);
}
- void OnLoaded(object sender, RoutedEventArgs args)
+ void canvas_OnLoaded(object sender, RoutedEventArgs args)
{
if (Page == null)
return;
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;
page.TopAppBar = null;
}
- void OnUnloaded(object sender, RoutedEventArgs args)
+ void canvas_OnUnloaded(object sender, RoutedEventArgs args)
{
RemoveTabs();
PageController?.SendDisappearing();
<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>
using System;
+using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Windows.UI.Xaml;
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);