summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT.Phone
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-04-18 09:46:51 -0700
committerJason Smith <jason.smith@xamarin.com>2016-04-18 09:46:51 -0700
commit75f112400223ea628ee008d311b7d5d54d98eafe (patch)
treeaf859c326a488cb0801fd57fca7bbce0cf0b4ad0 /Xamarin.Forms.Platform.WinRT.Phone
parentfc05a57e9dfa5b70e21b08f9c8f839b7986b4698 (diff)
downloadxamarin-forms-75f112400223ea628ee008d311b7d5d54d98eafe.tar.gz
xamarin-forms-75f112400223ea628ee008d311b7d5d54d98eafe.tar.bz2
xamarin-forms-75f112400223ea628ee008d311b7d5d54d98eafe.zip
BarBackgroundColor and BarTextColor on TabbedPage (#96)
* [Core] Add properties to TabbedPage * [Controls] Add properties to test page * [iOS] Added BarBackgroundColor & BarTextColor to TabbedPage * [A] Added BarBackgroundColor & BarTextColor to TabbedPage * [UWP] Added BarBackgroundColor & BarTextColor to TabbedPage * [WinRT] Format file * [WinRT] Added BarBackgroundColor & BarTextColor to TabbedPage * [Docs] Updated docs
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT.Phone')
-rw-r--r--Xamarin.Forms.Platform.WinRT.Phone/PhoneResources.xaml4
-rw-r--r--Xamarin.Forms.Platform.WinRT.Phone/TabbedPageRenderer.cs163
2 files changed, 103 insertions, 64 deletions
diff --git a/Xamarin.Forms.Platform.WinRT.Phone/PhoneResources.xaml b/Xamarin.Forms.Platform.WinRT.Phone/PhoneResources.xaml
index 61f6667e..4dcf4be5 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}" />
+ <TextBlock Text="{Binding Title}" Foreground="{TemplateBinding ToolbarForeground}" />
</DataTemplate>
</Setter.Value>
</Setter>
@@ -281,7 +281,7 @@
</Grid>
<ScrollViewer x:Name="ScrollViewer" HorizontalSnapPointsAlignment="Center" HorizontalSnapPointsType="MandatorySingle" HorizontalScrollBarVisibility="Hidden" Margin="{TemplateBinding Padding}" Grid.Row="1" Template="{StaticResource ScrollViewerScrollBarlessTemplate}" VerticalSnapPointsType="None" VerticalScrollBarVisibility="Disabled" VerticalScrollMode="Disabled" VerticalContentAlignment="Stretch" ZoomMode="Disabled">
<PivotPanel x:Name="Panel" VerticalAlignment="Stretch">
- <PivotHeaderPanel x:Name="Header">
+ <PivotHeaderPanel x:Name="Header" Background="{TemplateBinding ToolbarBackground}">
<PivotHeaderPanel.RenderTransform>
<CompositeTransform x:Name="HeaderTranslateTransform" TranslateX="0"/>
</PivotHeaderPanel.RenderTransform>
diff --git a/Xamarin.Forms.Platform.WinRT.Phone/TabbedPageRenderer.cs b/Xamarin.Forms.Platform.WinRT.Phone/TabbedPageRenderer.cs
index 9de3a623..a7337301 100644
--- a/Xamarin.Forms.Platform.WinRT.Phone/TabbedPageRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT.Phone/TabbedPageRenderer.cs
@@ -8,14 +8,15 @@ using Windows.UI.Xaml.Media;
namespace Xamarin.Forms.Platform.WinRT
{
- internal class TabbedPagePresenter : Windows.UI.Xaml.Controls.ContentPresenter
+ internal class TabbedPagePresenter : Windows.UI.Xaml.Controls.ContentPresenter
{
- public TabbedPagePresenter ()
+ public TabbedPagePresenter()
{
SizeChanged += (s, e) => {
- if (ActualWidth > 0 && ActualHeight > 0) {
- var tab = ((Page) DataContext);
- ((TabbedPage) tab.RealParent).ContainerArea = new Rectangle (0, 0, ActualWidth, ActualHeight);
+ if (ActualWidth > 0 && ActualHeight > 0)
+ {
+ var tab = ((Page)DataContext);
+ ((TabbedPage)tab.RealParent).ContainerArea = new Rectangle(0, 0, ActualWidth, ActualHeight);
}
};
}
@@ -36,7 +37,7 @@ namespace Xamarin.Forms.Platform.WinRT
get { return Element; }
}
- public Pivot Control
+ public FormsPivot Control
{
get;
private set;
@@ -48,31 +49,34 @@ namespace Xamarin.Forms.Platform.WinRT
private set;
}
- public void SetElement (VisualElement element)
+ public void SetElement(VisualElement element)
{
if (element != null && !(element is TabbedPage))
- throw new ArgumentException ("Element must be a TabbedPage", "element");
+ throw new ArgumentException("Element must be a TabbedPage", "element");
TabbedPage oldElement = Element;
- Element = (TabbedPage) element;
+ Element = (TabbedPage)element;
- if (oldElement != null) {
+ if (oldElement != null)
+ {
oldElement.PropertyChanged -= OnElementPropertyChanged;
- ((INotifyCollectionChanged) oldElement.Children).CollectionChanged -= OnPagesChanged;
+ ((INotifyCollectionChanged)oldElement.Children).CollectionChanged -= OnPagesChanged;
}
- if (element != null) {
- if (Control == null) {
+ if (element != null)
+ {
+ if (Control == null)
+ {
Control = new FormsPivot {
- Style = (Windows.UI.Xaml.Style) Windows.UI.Xaml.Application.Current.Resources["TabbedPageStyle"]
+ Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["TabbedPageStyle"]
};
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) {
- Element = (Page) element,
+ Tracker = new BackgroundTracker<Pivot>(Windows.UI.Xaml.Controls.Control.BackgroundProperty) {
+ Element = (Page)element,
Control = Control,
Container = Control
};
@@ -82,22 +86,24 @@ namespace Xamarin.Forms.Platform.WinRT
}
Control.DataContext = Element;
- OnPagesChanged (Element.Children, new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset));
- UpdateCurrentPage ();
-
- ((INotifyCollectionChanged) Element.Children).CollectionChanged += OnPagesChanged;
+ OnPagesChanged(Element.Children, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
+ UpdateCurrentPage();
+ UpdateBarTextColor();
+ UpdateBarBackgroundColor();
+
+ ((INotifyCollectionChanged)Element.Children).CollectionChanged += OnPagesChanged;
element.PropertyChanged += OnElementPropertyChanged;
- if (!string.IsNullOrEmpty (element.AutomationId))
- Control.SetValue (AutomationProperties.AutomationIdProperty, element.AutomationId);
+ if (!string.IsNullOrEmpty(element.AutomationId))
+ Control.SetValue(AutomationProperties.AutomationIdProperty, element.AutomationId);
}
- OnElementChanged (new VisualElementChangedEventArgs (oldElement, element));
+ OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));
}
- public SizeRequest GetDesiredSize (double widthConstraint, double heightConstraint)
+ public SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
{
- var constraint = new Windows.Foundation.Size (widthConstraint, heightConstraint);
+ var constraint = new Windows.Foundation.Size(widthConstraint, heightConstraint);
var oldWidth = Control.Width;
var oldHeight = Control.Height;
@@ -105,27 +111,27 @@ namespace Xamarin.Forms.Platform.WinRT
Control.Height = double.NaN;
Control.Width = double.NaN;
- Control.Measure (constraint);
- var result = new Size (Math.Ceiling (Control.DesiredSize.Width), Math.Ceiling (Control.DesiredSize.Height));
+ Control.Measure(constraint);
+ var result = new Size(Math.Ceiling(Control.DesiredSize.Width), Math.Ceiling(Control.DesiredSize.Height));
Control.Width = oldWidth;
Control.Height = oldHeight;
- return new SizeRequest (result);
+ return new SizeRequest(result);
}
- public void Dispose ()
+ public void Dispose()
{
- Dispose (true);
+ Dispose(true);
}
- protected virtual void Dispose (bool disposing)
+ protected virtual void Dispose(bool disposing)
{
if (!disposing || _disposed)
return;
_disposed = true;
- SetElement (null);
+ SetElement(null);
Tracker = null;
}
@@ -140,8 +146,9 @@ namespace Xamarin.Forms.Platform.WinRT
if (_tracker == value)
return;
- if (_tracker != null) {
- _tracker.Dispose ();
+ if (_tracker != null)
+ {
+ _tracker.Dispose();
/*this.tracker.Updated -= OnTrackerUpdated;*/
}
@@ -151,8 +158,8 @@ namespace Xamarin.Forms.Platform.WinRT
this.tracker.Updated += OnTrackerUpdated;*/
}
}
-
- bool ITitleProvider.ShowTitle
+
+ bool ITitleProvider.ShowTitle
{
get
{
@@ -164,12 +171,12 @@ namespace Xamarin.Forms.Platform.WinRT
if (_showTitle == value)
return;
_showTitle = value;
-
+
(Control as FormsPivot).ToolbarVisibility = _showTitle ? Visibility.Visible : Visibility.Collapsed;
}
}
- string ITitleProvider.Title
+ string ITitleProvider.Title
{
get
{
@@ -199,86 +206,118 @@ namespace Xamarin.Forms.Platform.WinRT
}
}
- protected virtual void OnElementChanged (VisualElementChangedEventArgs e)
+ protected virtual void OnElementChanged(VisualElementChangedEventArgs e)
{
var changed = ElementChanged;
if (changed != null)
- changed (this, e);
+ changed(this, e);
}
bool _disposed;
VisualElementTracker<Page, Pivot> _tracker;
bool _showTitle;
- void OnPagesChanged (object sender, NotifyCollectionChangedEventArgs e)
+ void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
{
- e.Apply (Element.Children, Control.Items);
+ e.Apply(Element.Children, Control.Items);
// Potential performance issue, UpdateLayout () is called for every page change
- Control.UpdateLayout ();
+ Control.UpdateLayout();
}
- void OnSelectionChanged (object sender, SelectionChangedEventArgs e)
+ void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (Element == null)
return;
- Page page = (e.AddedItems.Count > 0) ? (Page) e.AddedItems[0] : null;
+ Page page = (e.AddedItems.Count > 0) ? (Page)e.AddedItems[0] : null;
Element.CurrentPage = page;
}
- void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e)
+ void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
- if (e.PropertyName == "CurrentPage")
- UpdateCurrentPage ();
+ if (e.PropertyName == nameof(TabbedPage.CurrentPage))
+ UpdateCurrentPage();
+ else if (e.PropertyName == TabbedPage.BarTextColorProperty.PropertyName)
+ UpdateBarTextColor();
+ else if (e.PropertyName == TabbedPage.BarBackgroundColorProperty.PropertyName)
+ UpdateBarBackgroundColor();
}
- void UpdateCurrentPage ()
+ void UpdateCurrentPage()
{
Page page = Element.CurrentPage;
- UpdateTitle (page);
+ UpdateTitle(page);
if (page == null)
return;
Control.SelectedItem = page;
}
- void OnLoaded (object sender, RoutedEventArgs args)
+ void OnLoaded(object sender, RoutedEventArgs args)
{
if (Element == null)
return;
- Element.SendAppearing ();
+ Element.SendAppearing();
}
- void OnUnloaded (object sender, RoutedEventArgs args)
+ void OnUnloaded(object sender, RoutedEventArgs args)
{
if (Element == null)
return;
- Element.SendDisappearing ();
+ Element.SendDisappearing();
+ }
+
+ void OnTrackerUpdated(object sender, EventArgs e)
+ {
+
+ }
+
+ Brush GetBarBackgroundBrush()
+ {
+ object defaultColor = Windows.UI.Xaml.Application.Current.Resources["AppBarBackgroundThemeBrush"];
+ if (Element.BarBackgroundColor.IsDefault && defaultColor != null)
+ return (Brush)defaultColor;
+ return Element.BarBackgroundColor.ToBrush();
+ }
+
+ Brush GetBarForegroundBrush()
+ {
+ object defaultColor = Windows.UI.Xaml.Application.Current.Resources["AppBarItemForegroundThemeBrush"];
+ if (Element.BarTextColor.IsDefault)
+ return (Brush)defaultColor;
+ return Element.BarTextColor.ToBrush();
}
- void OnTrackerUpdated (object sender, EventArgs e)
+ void UpdateBarBackgroundColor()
{
+ Control.ToolbarBackground = GetBarBackgroundBrush();
+ }
+ void UpdateBarTextColor()
+ {
+ Control.ToolbarForeground = GetBarForegroundBrush();
}
- void UpdateTitle (Page child)
+ void UpdateTitle(Page child)
{
- Control.ClearValue (Pivot.TitleProperty);
+ Control.ClearValue(Pivot.TitleProperty);
if (child == null)
return;
- var renderer = Platform.GetRenderer (child);
+ var renderer = Platform.GetRenderer(child);
var navigationRenderer = renderer as NavigationPageRenderer;
- if (navigationRenderer != null) {
+ if (navigationRenderer != null)
+ {
Control.Title = navigationRenderer.Title;
- } else {
- ((ITitleProvider) this).ShowTitle = false;
+ }
+ else {
+ ((ITitleProvider)this).ShowTitle = false;
}
}
-
+
}
} \ No newline at end of file