diff options
author | Samantha Houts <samantha@teamredwall.com> | 2016-08-30 10:46:14 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-08-30 10:46:14 -0700 |
commit | 5e553f6195e66e48688b8ab324f1bab1e9251f0a (patch) | |
tree | f8843e5e9e8afe89a05a1cc91c3b7fa05588bac7 /Xamarin.Forms.Platform.UAP | |
parent | f551654b1cfe654c579ca50978445e7cb93f287d (diff) | |
download | xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.tar.gz xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.tar.bz2 xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.zip |
Platform Specifics (#301)
* Playing around with how the platform specifics interfaces etc. might work
* Sample implementation of iOS navigation translucency
* Very slightly reduced code
* Better vendor stuff
* Drop single-implemenation interfaces
* Generics on NavigationPage
* On-demand vendor stuff
* Remove functionally duplicate classes and make ControlGallery work again
* Namespace all the things. XAML test.
* Can use Effect to attach platform specific
* Attach Effect on PropertyChanging for XAML support!
* Rename IConfigPlatform interfaces for readability
* Some renaming to match the documents
* Split class files
* Clear out test-only code
* Re-namespace
* Added On method to rendered Elements
* Allow for removal of platform suffix, convenience methods on specific platforms
* Creating a gallery page for specifics
* Add rudimentary Platform Specifics gallery; make CollapseStyle work on UWP;
Add CollapsedPaneWidth specific property
* Toolbar now working with both collapse styles
* MDP now displaying Content title; toolbar routing around title
* Add a gallery for the iOS NavigationPage stuff
* Add Navigation Page as detail page to verify it works with new Toolbar options
* Make titlebar/toolbar background colors consistent
* ToolbarPlacement now working on NavigationPage
* Toolbar Placement working for tabbed and nav pages
* Fix bug where phone doesn't get default toolbar placement on start
* [Core] Add PS WindowSoftInputModeAdjust
[Core] Make Application extendable
* Toolbar placement now working on Nav, Tabbed, and Master pages on desktop/phone
Remove unnecessary style indirection
Fix build errors
* [A] Add PlatformConfigurationExtensions
* SetSoftInputMode test page
* [A] SetSoftInputMode
Known issue: Status bar color does not work in AdjustResize mode
* [Core] Add PS Blur
* [iOS] Configure renderer for blur
* Add test page
* Move to blur VisualElement for broader support
* Move test pages to gallery
* Update docs
* Use lazy initializer for PlatformConfigurationRegistry
Diffstat (limited to 'Xamarin.Forms.Platform.UAP')
-rw-r--r-- | Xamarin.Forms.Platform.UAP/FormsCommandBar.cs | 19 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.UAP/MasterDetailControl.cs | 100 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.UAP/MasterDetailControlStyle.xaml | 64 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.UAP/MasterDetailPageRenderer.cs | 36 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.UAP/PageControlStyle.xaml | 42 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.UAP/Resources.xaml | 261 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs | 603 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.UAP/TabbedPageStyle.xaml | 199 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.UAP/ToolbarPlacementHelper.cs | 46 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj | 16 |
10 files changed, 806 insertions, 580 deletions
diff --git a/Xamarin.Forms.Platform.UAP/FormsCommandBar.cs b/Xamarin.Forms.Platform.UAP/FormsCommandBar.cs index 2ca665af..21e9ca16 100644 --- a/Xamarin.Forms.Platform.UAP/FormsCommandBar.cs +++ b/Xamarin.Forms.Platform.UAP/FormsCommandBar.cs @@ -6,32 +6,23 @@ namespace Xamarin.Forms.Platform.UWP { public class FormsCommandBar : CommandBar { - Windows.UI.Xaml.Controls.Button _moreButton; + // TODO Once 10.0.14393.0 is available, enable dynamic overflow: https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.commandbar.isdynamicoverflowenabled.aspx public FormsCommandBar() { PrimaryCommands.VectorChanged += OnCommandsChanged; SecondaryCommands.VectorChanged += OnCommandsChanged; - } - - protected override void OnApplyTemplate() - { - base.OnApplyTemplate(); - _moreButton = GetTemplateChild("MoreButton") as Windows.UI.Xaml.Controls.Button; - UpdateMore(); + UpdateVisibility(); } void OnCommandsChanged(IObservableVector<ICommandBarElement> sender, IVectorChangedEventArgs args) { - UpdateMore(); + UpdateVisibility(); } - void UpdateMore() + void UpdateVisibility() { - if (_moreButton == null) - return; - - _moreButton.Visibility = PrimaryCommands.Count > 0 || SecondaryCommands.Count > 0 ? Visibility.Visible : Visibility.Collapsed; + Visibility = PrimaryCommands.Count + SecondaryCommands.Count > 0 ? Visibility.Visible : Visibility.Collapsed; } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.UAP/MasterDetailControl.cs b/Xamarin.Forms.Platform.UAP/MasterDetailControl.cs index 6787ccec..51f737f8 100644 --- a/Xamarin.Forms.Platform.UAP/MasterDetailControl.cs +++ b/Xamarin.Forms.Platform.UAP/MasterDetailControl.cs @@ -1,7 +1,9 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; +using Xamarin.Forms.PlatformConfiguration.WindowsSpecific; namespace Xamarin.Forms.Platform.UWP { @@ -17,9 +19,15 @@ namespace Xamarin.Forms.Platform.UWP public static readonly DependencyProperty IsPaneOpenProperty = DependencyProperty.Register("IsPaneOpen", typeof(bool), typeof(MasterDetailControl), new PropertyMetadata(default(bool))); - public static readonly DependencyProperty ShouldShowSplitModeProperty = DependencyProperty.Register("ShouldShowSplitMode", typeof(bool), typeof(MasterDetailControl), + public static readonly DependencyProperty ShouldShowSplitModeProperty = DependencyProperty.Register(nameof(ShouldShowSplitMode), typeof(bool), typeof(MasterDetailControl), new PropertyMetadata(default(bool), OnShouldShowSplitModeChanged)); + public static readonly DependencyProperty CollapseStyleProperty = DependencyProperty.Register(nameof(CollapseStyle), typeof(CollapseStyle), + typeof(MasterDetailControl), new PropertyMetadata(CollapseStyle.Full, CollapseStyleChanged)); + + public static readonly DependencyProperty CollapsedPaneWidthProperty = DependencyProperty.Register(nameof(CollapsedPaneWidth), typeof(double), typeof(MasterDetailControl), + new PropertyMetadata(48d, CollapsedPaneWidthChanged)); + public static readonly DependencyProperty DetailTitleProperty = DependencyProperty.Register("DetailTitle", typeof(string), typeof(MasterDetailControl), new PropertyMetadata(default(string))); public static readonly DependencyProperty ToolbarForegroundProperty = DependencyProperty.Register("ToolbarForeground", typeof(Brush), typeof(MasterDetailControl), @@ -37,20 +45,26 @@ namespace Xamarin.Forms.Platform.UWP public static readonly DependencyProperty MasterToolbarVisibilityProperty = DependencyProperty.Register("MasterToolbarVisibility", typeof(Visibility), typeof(MasterDetailControl), new PropertyMetadata(default(Visibility))); + public static readonly DependencyProperty ContentTogglePaneButtonVisibilityProperty = DependencyProperty.Register(nameof(ContentTogglePaneButtonVisibility), typeof(Visibility), typeof(MasterDetailControl), + new PropertyMetadata(default(Visibility))); + CommandBar _commandBar; + Border _bottomCommandBarArea; + Border _topCommandBarArea; TaskCompletionSource<CommandBar> _commandBarTcs; FrameworkElement _masterPresenter; FrameworkElement _detailPresenter; SplitView _split; + ToolbarPlacement _toolbarPlacement; - public MasterDetailControl() + public MasterDetailControl() { DefaultStyleKey = typeof(MasterDetailControl); - MasterTitleVisibility = Visibility.Collapsed; + DetailTitleVisibility = Visibility.Collapsed; - if (Device.Idiom != TargetIdiom.Phone) - MasterToolbarVisibility = Visibility.Collapsed; + + CollapseStyle = CollapseStyle.Full; } public FrameworkElement Detail @@ -148,6 +162,34 @@ namespace Xamarin.Forms.Platform.UWP set { SetValue(ShouldShowSplitModeProperty, value); } } + public CollapseStyle CollapseStyle + { + get { return (CollapseStyle)GetValue(CollapseStyleProperty); } + set { SetValue(CollapseStyleProperty, value); } + } + + public ToolbarPlacement ToolbarPlacement + { + get { return _toolbarPlacement; } + set + { + _toolbarPlacement = value; + UpdateToolbarPlacement(); + } + } + + public Visibility ContentTogglePaneButtonVisibility + { + get { return (Visibility)GetValue(ContentTogglePaneButtonVisibilityProperty); } + set { SetValue(ContentTogglePaneButtonVisibilityProperty, value); } + } + + public double CollapsedPaneWidth + { + get { return (double)GetValue(CollapsedPaneWidthProperty); } + set { SetValue(CollapsedPaneWidthProperty, value); } + } + public Brush ToolbarBackground { get { return (Brush)GetValue(ToolbarBackgroundProperty); } @@ -194,8 +236,11 @@ namespace Xamarin.Forms.Platform.UWP _detailPresenter = GetTemplateChild("DetailPresenter") as FrameworkElement; _commandBar = GetTemplateChild("CommandBar") as CommandBar; + _bottomCommandBarArea = GetTemplateChild("BottomCommandBarArea") as Border; + _topCommandBarArea = GetTemplateChild("TopCommandBarArea") as Border; - UpdateMode(); + UpdateToolbarPlacement(); + UpdateMode(); if (_commandBarTcs != null) _commandBarTcs.SetResult(_commandBar); @@ -206,6 +251,21 @@ namespace Xamarin.Forms.Platform.UWP ((MasterDetailControl)dependencyObject).UpdateMode(); } + static void CollapseStyleChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) + { + ((MasterDetailControl)dependencyObject).UpdateMode(); + } + + static void ToolbarPlacementChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) + { + ((MasterDetailControl)dependencyObject).UpdateToolbarPlacement(); + } + + static void CollapsedPaneWidthChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) + { + ((MasterDetailControl)dependencyObject).UpdateMode(); + } + void OnToggleClicked(object sender, RoutedEventArgs args) { IsPaneOpen = !IsPaneOpen; @@ -214,9 +274,33 @@ namespace Xamarin.Forms.Platform.UWP void UpdateMode() { if (_split == null) + { return; + } - _split.DisplayMode = ShouldShowSplitMode ? SplitViewDisplayMode.Inline : SplitViewDisplayMode.Overlay; + _split.DisplayMode = ShouldShowSplitMode + ? SplitViewDisplayMode.Inline + : CollapseStyle == CollapseStyle.Full ? SplitViewDisplayMode.Overlay : SplitViewDisplayMode.CompactOverlay; + + _split.CompactPaneLength = CollapsedPaneWidth; + + if (_split.DisplayMode == SplitViewDisplayMode.Inline) + { + // If we've determined that the pane will always be open, then there's no + // reason to display the show/hide pane button in the master + MasterToolbarVisibility = Visibility.Collapsed; + } + + // If we're in compact mode or the pane is always open, + // we don't need to display the content pane's toggle button + ContentTogglePaneButtonVisibility = _split.DisplayMode == SplitViewDisplayMode.Overlay + ? Visibility.Visible + : Visibility.Collapsed; + } + + void UpdateToolbarPlacement() + { + ToolbarPlacementHelper.UpdateToolbarPlacement(_commandBar, ToolbarPlacement, _bottomCommandBarArea, _topCommandBarArea); } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.UAP/MasterDetailControlStyle.xaml b/Xamarin.Forms.Platform.UAP/MasterDetailControlStyle.xaml new file mode 100644 index 00000000..d82f78af --- /dev/null +++ b/Xamarin.Forms.Platform.UAP/MasterDetailControlStyle.xaml @@ -0,0 +1,64 @@ +<ResourceDictionary + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:uwp="using:Xamarin.Forms.Platform.UWP"> + <Style TargetType="uwp:MasterDetailControl"> + <Setter Property="ToolbarForeground" Value="{ThemeResource DefaultTextForegroundThemeBrush}" /> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="uwp:MasterDetailControl"> + <SplitView x:Name="SplitView" IsPaneOpen="{Binding IsPaneOpen,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}" DisplayMode="Overlay"> + <SplitView.Pane> + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="*" /> + </Grid.RowDefinitions> + <StackPanel Grid.Row="0" Orientation="Horizontal" Visibility="{TemplateBinding MasterToolbarVisibility}" Background="{TemplateBinding ToolbarBackground}"> + <Button Name="PaneTogglePane" Style="{ThemeResource PaneButton}" Foreground="{TemplateBinding ToolbarForeground}" /> + <TextBlock Margin="10,0,0,0" Style="{ThemeResource TitleTextBlockStyle}" VerticalAlignment="Center" Text="{TemplateBinding MasterTitle}" Visibility="{TemplateBinding MasterTitleVisibility}" Foreground="{TemplateBinding ToolbarForeground}"/> + </StackPanel> + <ContentPresenter x:Name="MasterPresenter" Grid.Row="1" Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Master}" /> + </Grid> + </SplitView.Pane> + <SplitView.Content> + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="*" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + + <Grid x:Name="TitleBar" Background="{TemplateBinding ToolbarBackground}" HorizontalAlignment="Stretch"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="Auto"></ColumnDefinition> + <ColumnDefinition Width="*"></ColumnDefinition> + </Grid.ColumnDefinitions> + + <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Background="{TemplateBinding ToolbarBackground}" > + + <Button Name="ContentTogglePane" Style="{ThemeResource PaneButton}" Foreground="{TemplateBinding ToolbarForeground}" + Visibility="{TemplateBinding ContentTogglePaneButtonVisibility}" /> + + <Border Height="{ThemeResource TitleBarHeight}" Visibility="{TemplateBinding DetailTitleVisibility}"> + <TextBlock Text="{TemplateBinding DetailTitle}" VerticalAlignment="Center" Margin="10,0,0,0" Foreground="{TemplateBinding ToolbarForeground}" Style="{ThemeResource TitleTextBlockStyle}" /> + </Border> + + </StackPanel> + + <Border x:Name="TopCommandBarArea" Grid.Column="1" HorizontalAlignment="Stretch"> + <uwp:FormsCommandBar x:Name="CommandBar" VerticalContentAlignment="Top" Background="{TemplateBinding ToolbarBackground}" Height="{ThemeResource TitleBarHeight}" /> + </Border> + </Grid> + + <ContentPresenter x:Name="DetailPresenter" Grid.Row="1" Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Detail}" /> + + <Border x:Name="BottomCommandBarArea" Grid.Row="2" HorizontalAlignment="Stretch"></Border> + </Grid> + </SplitView.Content> + </SplitView> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> +</ResourceDictionary>
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.UAP/MasterDetailPageRenderer.cs b/Xamarin.Forms.Platform.UAP/MasterDetailPageRenderer.cs index c424c7fe..f0048154 100644 --- a/Xamarin.Forms.Platform.UAP/MasterDetailPageRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/MasterDetailPageRenderer.cs @@ -6,6 +6,8 @@ using Windows.UI.Xaml.Automation; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Media; +using Xamarin.Forms.PlatformConfiguration.WindowsSpecific; +using Specifics = Xamarin.Forms.PlatformConfiguration.WindowsSpecific.MasterDetailPage; namespace Xamarin.Forms.Platform.UWP { @@ -56,7 +58,7 @@ namespace Xamarin.Forms.Platform.UWP set { Control.ToolbarForeground = value; } } -IPageController PageController => Element as IPageController; + IPageController PageController => Element as IPageController; IMasterDetailPageController MasterDetailPageController => Element as IMasterDetailPageController; @@ -68,11 +70,9 @@ IPageController PageController => Element as IPageController; { if (_showTitle == value) return; + _showTitle = value; - if (_showTitle) - Control.DetailTitleVisibility = Visibility.Visible; - else - Control.DetailTitleVisibility = Visibility.Collapsed; + Control.DetailTitleVisibility = _showTitle ? Visibility.Visible : Visibility.Collapsed; } } @@ -132,7 +132,7 @@ IPageController PageController => Element as IPageController; { Control = new MasterDetailControl(); Control.Loaded += OnControlLoaded; - Control.Unloaded += OnControlUnlaoded; + Control.Unloaded += OnControlUnloaded; Control.SizeChanged += OnNativeSizeChanged; Control.RegisterPropertyChangedCallback(MasterDetailControl.IsPaneOpenProperty, OnIsPaneOpenChanged); @@ -148,7 +148,12 @@ IPageController PageController => Element as IPageController; if (!string.IsNullOrEmpty(e.NewElement.AutomationId)) Control.SetValue(AutomationProperties.AutomationIdProperty, e.NewElement.AutomationId); - } + +#if WINDOWS_UWP + UpdateToolbarPlacement(); +#endif + + } } protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) @@ -159,8 +164,12 @@ IPageController PageController => Element as IPageController; UpdateMaster(); else if (e.PropertyName == "Detail") UpdateDetail(); - else if (e.PropertyName == "ShouldShowSplitMode") + else if (e.PropertyName == nameof(MasterDetailControl.ShouldShowSplitMode) + || e.PropertyName == Specifics.CollapseStyleProperty.PropertyName + || e.PropertyName == Specifics.CollapsedPaneWidthProperty.PropertyName) UpdateMode(); + else if(e.PropertyName == PlatformConfiguration.WindowsSpecific.Page.ToolbarPlacementProperty.PropertyName) + UpdateToolbarPlacement(); } void ClearDetail() @@ -202,7 +211,7 @@ IPageController PageController => Element as IPageController; UpdateBounds(); } - void OnControlUnlaoded(object sender, RoutedEventArgs routedEventArgs) + void OnControlUnloaded(object sender, RoutedEventArgs routedEventArgs) { PageController?.SendDisappearing(); } @@ -264,6 +273,7 @@ IPageController PageController => Element as IPageController; return; Control.DetailTitle = (_detail as NavigationPage)?.CurrentPage?.Title ?? _detail.Title ?? Element?.Title; + (this as ITitleProvider).ShowTitle = !string.IsNullOrEmpty(Control.DetailTitle); } void UpdateIsPresented() @@ -291,10 +301,18 @@ IPageController PageController => Element as IPageController; void UpdateMode() { + Control.CollapseStyle = Element.OnThisPlatform().GetCollapseStyle(); + Control.CollapsedPaneWidth = Element.OnThisPlatform().CollapsedPaneWidth(); Control.ShouldShowSplitMode = MasterDetailPageController.ShouldShowSplitMode; } #if WINDOWS_UWP + + void UpdateToolbarPlacement() + { + Control.ToolbarPlacement = Element.OnThisPlatform().GetToolbarPlacement(); + } + public void BindForegroundColor(AppBar appBar) { SetAppBarForegroundBinding(appBar); diff --git a/Xamarin.Forms.Platform.UAP/PageControlStyle.xaml b/Xamarin.Forms.Platform.UAP/PageControlStyle.xaml new file mode 100644 index 00000000..bd199487 --- /dev/null +++ b/Xamarin.Forms.Platform.UAP/PageControlStyle.xaml @@ -0,0 +1,42 @@ +<ResourceDictionary + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:uwp="using:Xamarin.Forms.Platform.UWP"> + <Style TargetType="uwp:PageControl"> + <Setter Property="ContentMargin" Value="0" /> + <Setter Property="TitleBrush" Value="{ThemeResource DefaultTextForegroundThemeBrush}" /> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="uwp:PageControl"> + <Grid Background="{TemplateBinding Background}"> + + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="*" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + + <Grid x:Name="TitleBar" Background="{TemplateBinding ToolbarBackground}" HorizontalAlignment="Stretch"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="Auto"></ColumnDefinition> + <ColumnDefinition Width="*"></ColumnDefinition> + </Grid.ColumnDefinitions> + + <Border Height="{ThemeResource TitleBarHeight}" Visibility="{TemplateBinding TitleVisibility}"> + <TextBlock Text="{Binding Title}" VerticalAlignment="Center" Padding="10,0,0,0" Foreground="{TemplateBinding TitleBrush}" Style="{ThemeResource TitleTextBlockStyle}" /> + </Border> + + <Border x:Name="TopCommandBarArea" Grid.Column="1" HorizontalAlignment="Stretch"> + <uwp:FormsCommandBar x:Name="CommandBar" Background="{TemplateBinding ToolbarBackground}" Height="{ThemeResource TitleBarHeight}" /> + </Border> + </Grid> + + <ContentPresenter Margin="{TemplateBinding ContentMargin}" ContentTransitions="{TemplateBinding ContentTransitions}" x:Name="presenter" Grid.Row="1" /> + + <Border x:Name="BottomCommandBarArea" Grid.Row="2" HorizontalAlignment="Stretch"></Border> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> +</ResourceDictionary>
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.UAP/Resources.xaml b/Xamarin.Forms.Platform.UAP/Resources.xaml index 5f3a4999..732283e8 100644 --- a/Xamarin.Forms.Platform.UAP/Resources.xaml +++ b/Xamarin.Forms.Platform.UAP/Resources.xaml @@ -5,8 +5,11 @@ x:Class="Xamarin.Forms.Platform.UWP.Resources"> <ResourceDictionary.MergedDictionaries> + <ResourceDictionary Source="PageControlStyle.xaml" /> <ResourceDictionary Source="FormsTextBoxStyle.xaml" /> <ResourceDictionary Source="AutoSuggestStyle.xaml" /> + <ResourceDictionary Source="MasterDetailControlStyle.xaml" /> + <ResourceDictionary Source="TabbedPageStyle.xaml" /> </ResourceDictionary.MergedDictionaries> <uwp:CaseConverter x:Key="LowerConverter" ConvertToUpper="False" /> @@ -247,52 +250,7 @@ </Setter> </Style> - <Style TargetType="uwp:MasterDetailControl"> - <Setter Property="ToolbarForeground" Value="{ThemeResource DefaultTextForegroundThemeBrush}" /> - <Setter Property="Template"> - <Setter.Value> - <ControlTemplate TargetType="uwp:MasterDetailControl"> - <SplitView x:Name="SplitView" IsPaneOpen="{Binding IsPaneOpen,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}" DisplayMode="Overlay"> - <SplitView.Pane> - <Grid> - <Grid.RowDefinitions> - <RowDefinition Height="Auto" /> - <RowDefinition Height="*" /> - </Grid.RowDefinitions> - <StackPanel Grid.Row="0" Orientation="Horizontal" Visibility="{TemplateBinding MasterToolbarVisibility}" Background="{TemplateBinding ToolbarBackground}"> - <Button Name="PaneTogglePane" Style="{ThemeResource PaneButton}" Foreground="{TemplateBinding ToolbarForeground}" /> - <TextBlock Style="{ThemeResource TitleTextBlockStyle}" VerticalAlignment="Center" Text="{TemplateBinding MasterTitle}" Visibility="{TemplateBinding MasterTitleVisibility}" Foreground="{TemplateBinding ToolbarForeground}"/> - </StackPanel> - - <ContentPresenter x:Name="MasterPresenter" Grid.Row="1" Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Master}" /> - </Grid> - </SplitView.Pane> - <SplitView.Content> - <Grid> - <Grid.RowDefinitions> - <RowDefinition Height="Auto" /> - <RowDefinition Height="*" /> - </Grid.RowDefinitions> - - <uwp:FormsCommandBar x:Name="CommandBar" Grid.Row="0" Foreground="{TemplateBinding ToolbarForeground}" Background="{TemplateBinding ToolbarBackground}" Visibility="{TemplateBinding DetailTitleVisibility}" VerticalContentAlignment="Top"> - <uwp:FormsCommandBar.Content> - <StackPanel Orientation="Horizontal" VerticalAlignment="Center"> - <Button Name="ContentTogglePane" Style="{ThemeResource PaneButton}" Foreground="{TemplateBinding ToolbarForeground}" Visibility="{Binding ElementName=SplitView,Path=IsPaneOpen,Converter={StaticResource InvertedBoolVisibilityConverter}}" /> - <ContentControl VerticalAlignment="Top" VerticalContentAlignment="Center" Height="{StaticResource TitleBarHeight}"> - <TextBlock Text="{TemplateBinding DetailTitle}" Margin="10,0,0,0" Foreground="{TemplateBinding ToolbarForeground}" Style="{ThemeResource TitleTextBlockStyle}" /> - </ContentControl> - </StackPanel> - </uwp:FormsCommandBar.Content> - </uwp:FormsCommandBar> - - <ContentPresenter x:Name="DetailPresenter" Grid.Row="1" Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Detail}" /> - </Grid> - </SplitView.Content> - </SplitView> - </ControlTemplate> - </Setter.Value> - </Setter> - </Style> + <Style x:Key="FormsListViewItem" TargetType="ListViewItem"> <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" /> @@ -470,215 +428,6 @@ </uwp:EntryCellTextBox> </DataTemplate> - <Style x:Key="TabbedPageStyle" TargetType="uwp:FormsPivot"> - <Setter Property="HeaderTemplate"> - <Setter.Value> - <DataTemplate> - <TextBlock Name="TabbedPageHeaderTextBlock" Text="{Binding Title}" Style="{ThemeResource BodyTextBlockStyle}" /> - </DataTemplate> - </Setter.Value> - </Setter> - - <Setter Property="ItemTemplate"> - <Setter.Value> - <DataTemplate> - <uwp:TabbedPagePresenter Content="{Binding}" ContentTemplate="{ThemeResource ContainedPageTemplate}" /> - </DataTemplate> - </Setter.Value> - </Setter> - - <Setter Property="Template"> - <Setter.Value> - <ControlTemplate TargetType="uwp:FormsPivot"> - <Grid x:Name="RootElement" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}"> - <Grid.RowDefinitions> - <RowDefinition Height="Auto"/> - <RowDefinition Height="*"/> - </Grid.RowDefinitions> - <VisualStateManager.VisualStateGroups> - <VisualStateGroup x:Name="NavigationButtonsVisibility"> - <VisualState x:Name="NavigationButtonsHidden"/> - <VisualState x:Name="NavigationButtonsVisible"> - <Storyboard> - <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="NextButton"> - <DiscreteObjectKeyFrame KeyTime="0" Value="1"/> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsEnabled" Storyboard.TargetName="NextButton"> - <DiscreteObjectKeyFrame KeyTime="0" Value="True"/> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PreviousButton"> - <DiscreteObjectKeyFrame KeyTime="0" Value="1"/> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsEnabled" Storyboard.TargetName="PreviousButton"> - <DiscreteObjectKeyFrame KeyTime="0" Value="True"/> - </ObjectAnimationUsingKeyFrames> - </Storyboard> - </VisualState> - </VisualStateGroup> - <VisualStateGroup x:Name="HeaderStates"> - <VisualState x:Name="HeaderDynamic"/> - <VisualState x:Name="HeaderStatic"> - <Storyboard> - <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="Header"> - <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="StaticHeader"> - <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/> - </ObjectAnimationUsingKeyFrames> - </Storyboard> - </VisualState> - </VisualStateGroup> - </VisualStateManager.VisualStateGroups> - <uwp:FormsCommandBar x:Name="CommandBar" Grid.Row="0" VerticalContentAlignment="Top" Background="{TemplateBinding ToolbarBackground}" Visibility="{TemplateBinding ToolbarVisibility}" > - <uwp:FormsCommandBar.Content> - <ContentControl VerticalAlignment="Top" VerticalContentAlignment="Center" Height="{ThemeResource TitleBarHeight}" > - <TextBlock Text="{TemplateBinding Title}" VerticalAlignment="Center" Padding="10,0,0,0" Foreground="{TemplateBinding ToolbarForeground}" Style="{ThemeResource TitleTextBlockStyle}" /> - </ContentControl> - </uwp:FormsCommandBar.Content> - </uwp:FormsCommandBar> - <Grid Grid.Row="1"> - <Grid.Resources> - <ControlTemplate x:Key="NextTemplate" TargetType="Button"> - <Border x:Name="Root" BorderBrush="{ThemeResource SystemControlForegroundTransparentBrush}" BorderThickness="{ThemeResource PivotNavButtonBorderThemeThickness}" Background="{ThemeResource SystemControlBackgroundBaseMediumLowBrush}"> - <VisualStateManager.VisualStateGroups> - <VisualStateGroup x:Name="CommonStates"> - <VisualState x:Name="Normal"/> - <VisualState x:Name="PointerOver"> - <Storyboard> - <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Root"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseMediumBrush}"/> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="Arrow"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltAltMediumHighBrush}"/> - </ObjectAnimationUsingKeyFrames> - </Storyboard> - </VisualState> - <VisualState x:Name="Pressed"> - <Storyboard> - <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Root"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseMediumHighBrush}"/> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="Arrow"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltAltMediumHighBrush}"/> - </ObjectAnimationUsingKeyFrames> - </Storyboard> - </VisualState> - </VisualStateGroup> - </VisualStateManager.VisualStateGroups> - <FontIcon x:Name="Arrow" Foreground="{ThemeResource SystemControlForegroundAltMediumHighBrush}" FontSize="12" FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="" HorizontalAlignment="Center" MirroredWhenRightToLeft="True" UseLayoutRounding="False" VerticalAlignment="Center"/> - </Border> - </ControlTemplate> - <ControlTemplate x:Key="PreviousTemplate" TargetType="Button"> - <Border x:Name="Root" BorderBrush="{ThemeResource SystemControlForegroundTransparentBrush}" BorderThickness="{ThemeResource PivotNavButtonBorderThemeThickness}" Background="{ThemeResource SystemControlBackgroundBaseMediumLowBrush}"> - <VisualStateManager.VisualStateGroups> - <VisualStateGroup x:Name="CommonStates"> - <VisualState x:Name="Normal"/> - <VisualState x:Name="PointerOver"> - <Storyboard> - <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Root"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseMediumBrush}"/> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="Arrow"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltAltMediumHighBrush}"/> - </ObjectAnimationUsingKeyFrames> - </Storyboard> - </VisualState> - <VisualState x:Name="Pressed"> - <Storyboard> - <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Root"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseMediumHighBrush}"/> - </ObjectAnimationUsingKeyFrames> - <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="Arrow"> - <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltAltMediumHighBrush}"/> - </ObjectAnimationUsingKeyFrames> - </Storyboard> - </VisualState> - </VisualStateGroup> - </VisualStateManager.VisualStateGroups> - <FontIcon x:Name="Arrow" Foreground="{ThemeResource SystemControlForegroundAltMediumHighBrush}" FontSize="12" FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="" HorizontalAlignment="Center" MirroredWhenRightToLeft="True" UseLayoutRounding="False" VerticalAlignment="Center"/> - </Border> - </ControlTemplate> - </Grid.Resources> - <ScrollViewer x:Name="ScrollViewer" BringIntoViewOnFocusChange="False" HorizontalSnapPointsAlignment="Center" HorizontalSnapPointsType="MandatorySingle" HorizontalScrollBarVisibility="Hidden" Margin="{TemplateBinding Padding}" Template="{StaticResource ScrollViewerScrollBarlessTemplate}" VerticalSnapPointsType="None" VerticalScrollBarVisibility="Disabled" VerticalScrollMode="Disabled" VerticalContentAlignment="Stretch" ZoomMode="Disabled"> - <PivotPanel x:Name="Panel" VerticalAlignment="Stretch"> - <Grid x:Name="PivotLayoutElement"> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="Auto"/> - <ColumnDefinition Width="*"/> - <ColumnDefinition Width="Auto"/> - </Grid.ColumnDefinitions> - <Grid.RowDefinitions> - <RowDefinition Height="Auto"/> - <RowDefinition Height="*"/> - </Grid.RowDefinitions> - <Grid.RenderTransform> - <CompositeTransform x:Name="PivotLayoutElementTranslateTransform"/> - </Grid.RenderTransform> - <ContentPresenter x:Name="LeftHeaderPresenter" ContentTemplate="{TemplateBinding LeftHeaderTemplate}" Content="{TemplateBinding LeftHeader}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> - <ContentControl x:Name="HeaderClipper" Grid.Column="1" HorizontalContentAlignment="Stretch" UseSystemFocusVisuals="True"> - <ContentControl.Clip> - <RectangleGeometry x:Name="HeaderClipperGeometry"/> - </ContentControl.Clip> - <Grid Name="TabbedPageHeaderGrid" Background="{TemplateBinding ToolbarBackground}"> - <PivotHeaderPanel x:Name="StaticHeader" Visibility="Collapsed"/> - <PivotHeaderPanel x:Name="Header"> - <PivotHeaderPanel.RenderTransform> - <TransformGroup> - <CompositeTransform x:Name="HeaderTranslateTransform"/> - <CompositeTransform x:Name="HeaderOffsetTranslateTransform"/> - </TransformGroup> - </PivotHeaderPanel.RenderTransform> - </PivotHeaderPanel> - </Grid> - </ContentControl> - <Button x:Name="PreviousButton" Background="Transparent" Grid.Column="1" HorizontalAlignment="Left" Height="36" IsTabStop="False" IsEnabled="False" Margin="{ThemeResource PivotNavButtonMargin}" Opacity="0" Template="{StaticResource PreviousTemplate}" UseSystemFocusVisuals="False" VerticalAlignment="Top" Width="20"/> - <Button x:Name="NextButton" Background="Transparent" Grid.Column="1" HorizontalAlignment="Right" Height="36" IsTabStop="False" IsEnabled="False" Margin="{ThemeResource PivotNavButtonMargin}" Opacity="0" Template="{StaticResource NextTemplate}" UseSystemFocusVisuals="False" VerticalAlignment="Top" Width="20"/> - <ContentPresenter x:Name="RightHeaderPresenter" ContentTemplate="{TemplateBinding RightHeaderTemplate}" Content="{TemplateBinding RightHeader}" Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> - <ItemsPresenter x:Name="PivotItemPresenter" Grid.ColumnSpan="3" Grid.Row="1"> - <ItemsPresenter.RenderTransform> - <TransformGroup> - <TranslateTransform x:Name="ItemsPresenterTranslateTransform"/> - <CompositeTransform x:Name="ItemsPresenterCompositeTransform"/> - </TransformGroup> - </ItemsPresenter.RenderTransform> - </ItemsPresenter> - </Grid> - </PivotPanel> - </ScrollViewer> - </Grid> - </Grid> - </ControlTemplate> - </Setter.Value> - </Setter> - </Style> - - <Style x:Key="PageControlDefaultStyle" TargetType="uwp:PageControl"> - <Setter Property="ContentMargin" Value="0" /> - <Setter Property="TitleBrush" Value="{ThemeResource DefaultTextForegroundThemeBrush}" /> - <Setter Property="Template"> - <Setter.Value> - <ControlTemplate TargetType="uwp:PageControl"> - <Grid Background="{TemplateBinding Background}"> - <Grid.RowDefinitions> - <RowDefinition Height="Auto" /> - <RowDefinition Height="*" /> - </Grid.RowDefinitions> - - <uwp:FormsCommandBar x:Name="CommandBar" Grid.Row="0" VerticalContentAlignment="Top" Background="{TemplateBinding NavigationBarBackground}" Visibility="{Binding ShowNavigationBar,RelativeSource={RelativeSource Mode=TemplatedParent},Converter={StaticResource BoolVisibilityConverter}}"> - <uwp:FormsCommandBar.Content> - <ContentControl VerticalAlignment="Top" VerticalContentAlignment="Center" Height="{ThemeResource TitleBarHeight}"> - <TextBlock Text="{Binding Title}" VerticalAlignment="Center" Padding="10,0,0,0" Foreground="{TemplateBinding TitleBrush}" Style="{ThemeResource TitleTextBlockStyle}" /> - </ContentControl> - </uwp:FormsCommandBar.Content> - </uwp:FormsCommandBar> - - <ContentPresenter Margin="{TemplateBinding ContentMargin}" ContentTransitions="{TemplateBinding ContentTransitions}" x:Name="presenter" Grid.Row="1" /> - </Grid> - </ControlTemplate> - </Setter.Value> - </Setter> - </Style> - <Style TargetType="uwp:StepperControl"> <Setter Property="Template"> <Setter.Value> @@ -697,8 +446,6 @@ </Setter> </Style> - <Style TargetType="uwp:PageControl" BasedOn="{StaticResource PageControlDefaultStyle}" /> - <Style TargetType="TextBox"> <Setter Property="Margin" Value="0" /> </Style> diff --git a/Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs b/Xamarin.Forms.Platform.UAP/TabbedPageRenderer.cs index aa988b80..e9bbd4a1 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 Xamarin.Forms.PlatformConfiguration.WindowsSpecific; using WGrid = Windows.UI.Xaml.Controls.Grid; namespace Xamarin.Forms.Platform.UWP @@ -40,302 +41,320 @@ 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; } - - protected VisualElementTracker<Page, Pivot> Tracker - { - get { return _tracker; } - set - { - if (_tracker == value) - return; - - if (_tracker != null) - _tracker.Dispose(); - - _tracker = value; - } - } - - public void Dispose() - { - Dispose(true); - } - - Brush ITitleProvider.BarBackgroundBrush - { - set { Control.ToolbarBackground = value; } - } - - Brush ITitleProvider.BarForegroundBrush - { - set { Control.ToolbarForeground = value; } - } - - IPageController PageController => Element as IPageController; - - bool ITitleProvider.ShowTitle - { - get { return _showTitle; } - - set - { - if (_showTitle == value) - return; - _showTitle = value; - - UpdateBarVisibility(); - } - } - - string ITitleProvider.Title - { - get { return (string)Control?.Title; } - - set - { - if (Control != null && _showTitle) - Control.Title = value; - } - } - - public Task<CommandBar> GetCommandBarAsync() - { - return (Control as IToolbarProvider)?.GetCommandBarAsync(); - } - - public FrameworkElement ContainerElement - { - get { return Control; } - } - - VisualElement IVisualElementRenderer.Element - { - get { return Element; } - } - - public event EventHandler<VisualElementChangedEventArgs> ElementChanged; - - public SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) - { - var constraint = new Windows.Foundation.Size(widthConstraint, heightConstraint); - - double oldWidth = Control.Width; - double oldHeight = Control.Height; - - 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.Width = oldWidth; - Control.Height = oldHeight; - - return new SizeRequest(result); - } - - public void SetElement(VisualElement element) - { - if (element != null && !(element is TabbedPage)) - throw new ArgumentException("Element must be a TabbedPage", "element"); - - TabbedPage oldElement = Element; - Element = (TabbedPage)element; - - if (oldElement != null) - { - oldElement.PropertyChanged -= OnElementPropertyChanged; - ((INotifyCollectionChanged)oldElement.Children).CollectionChanged -= OnPagesChanged; - } - - if (element != null) - { - if (Control == null) - { - Control = new FormsPivot { Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["TabbedPageStyle"], }; - - Control.SelectionChanged += OnSelectionChanged; - - Tracker = new BackgroundTracker<Pivot>(Windows.UI.Xaml.Controls.Control.BackgroundProperty) { Element = (Page)element, Control = Control, Container = Control }; + public class TabbedPageRenderer : IVisualElementRenderer, ITitleProvider, IToolbarProvider + { + const string TabBarHeaderTextBlockName = "TabbedPageHeaderTextBlock"; + const string TabBarHeaderGridName = "TabbedPageHeaderGrid"; - Control.Loaded += OnLoaded; - Control.Unloaded += OnUnloaded; - } - - Control.DataContext = Element; - OnPagesChanged(Element.Children, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); - - UpdateCurrentPage(); - - ((INotifyCollectionChanged)Element.Children).CollectionChanged += OnPagesChanged; - element.PropertyChanged += OnElementPropertyChanged; - - if (!string.IsNullOrEmpty(element.AutomationId)) - Control.SetValue(AutomationProperties.AutomationIdProperty, element.AutomationId); - } - - OnElementChanged(new VisualElementChangedEventArgs(oldElement, element)); - } - - protected virtual void Dispose(bool disposing) - { - if (!disposing || _disposed) - return; - - _disposed = true; - PageController?.SendDisappearing(); - SetElement(null); - Tracker = null; - } - - protected virtual void OnElementChanged(VisualElementChangedEventArgs e) - { - EventHandler<VisualElementChangedEventArgs> changed = ElementChanged; - if (changed != null) - changed(this, e); - } - - 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) - { - e.Apply(Element.Children, Control.Items); - - // Potential performance issue, UpdateLayout () is called for every page change - Control.UpdateLayout(); - } - - void OnSelectionChanged(object sender, SelectionChangedEventArgs e) - { - if (Element == null) - return; - - Page page = e.AddedItems.Count > 0 ? (Page)e.AddedItems[0] : null; - Page currentPage = Element.CurrentPage; - if (currentPage == page) - return; - ((IPageController)currentPage)?.SendDisappearing(); - Element.CurrentPage = page; - ((IPageController)page)?.SendAppearing(); - } - - void OnUnloaded(object sender, RoutedEventArgs args) - { - PageController?.SendDisappearing(); - } - - Brush GetBarBackgroundBrush() - { - object defaultColor = Windows.UI.Xaml.Application.Current.Resources["SystemControlBackgroundChromeMediumLowBrush"]; - if (Element.BarBackgroundColor.IsDefault && defaultColor != null) - return (Brush)defaultColor; - return Element.BarBackgroundColor.ToBrush(); - } - - Brush GetBarForegroundBrush() - { - object defaultColor = Windows.UI.Xaml.Application.Current.Resources["ApplicationForegroundThemeBrush"]; - if (Element.BarTextColor.IsDefault && defaultColor != null) - return (Brush)defaultColor; - return Element.BarTextColor.ToBrush(); - } - - void UpdateBarBackgroundColor() - { - 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() - { - if (Element == null) return; - var barTextColor = Element.BarTextColor; - - if (barTextColor == _barTextColor) return; - _barTextColor = barTextColor; + Color _barBackgroundColor; + Color _barTextColor; + bool _disposed; + bool _showTitle; + VisualElementTracker<Page, Pivot> _tracker; - var controlToolbarForeground = Control.ToolbarForeground; - if (controlToolbarForeground == null && barTextColor.IsDefault) return; + ITitleProvider TitleProvider => this; - var brush = GetBarForegroundBrush(); - if (brush == controlToolbarForeground) - return; + public FormsPivot Control { get; private set; } - TitleProvider.BarForegroundBrush = brush; + public TabbedPage Element { get; private set; } - foreach (TextBlock tabBarTextBlock in Control.GetDescendantsByName<TextBlock>(TabBarHeaderTextBlockName)) - { - tabBarTextBlock.Foreground = brush; - } - } + protected VisualElementTracker<Page, Pivot> Tracker + { + get { return _tracker; } + set + { + if (_tracker == value) + return; - void UpdateBarVisibility() - { - Control.ToolbarVisibility = _showTitle ? Visibility.Visible : Visibility.Collapsed; - } - - void UpdateCurrentPage() - { - Page page = Element.CurrentPage; - - var nav = page as NavigationPage; - TitleProvider.ShowTitle = nav != null; - - if (page == null) - return; - - Control.SelectedItem = page; - } - } + if (_tracker != null) + _tracker.Dispose(); + + _tracker = value; + } + } + + public void Dispose() + { + Dispose(true); + } + + Brush ITitleProvider.BarBackgroundBrush + { + set { Control.ToolbarBackground = value; } + } + + Brush ITitleProvider.BarForegroundBrush + { + set { Control.ToolbarForeground = value; } + } + + IPageController PageController => Element as IPageController; + + bool ITitleProvider.ShowTitle + { + get { return _showTitle; } + + set + { + if (_showTitle == value) + return; + _showTitle = value; + + UpdateTitleVisibility(); + } + } + + string ITitleProvider.Title + { + get { return (string)Control?.Title; } + + set + { + if (Control != null && _showTitle) + Control.Title = value; + } + } + + public Task<CommandBar> GetCommandBarAsync() + { + return (Control as IToolbarProvider)?.GetCommandBarAsync(); + } + + public FrameworkElement ContainerElement + { + get { return Control; } + } + + VisualElement IVisualElementRenderer.Element + { + get { return Element; } + } + + public event EventHandler<VisualElementChangedEventArgs> ElementChanged; + + public SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) + { + var constraint = new Windows.Foundation.Size(widthConstraint, heightConstraint); + + double oldWidth = Control.Width; + double oldHeight = Control.Height; + + 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.Width = oldWidth; + Control.Height = oldHeight; + + return new SizeRequest(result); + } + + public void SetElement(VisualElement element) + { + if (element != null && !(element is TabbedPage)) + throw new ArgumentException("Element must be a TabbedPage", "element"); + + TabbedPage oldElement = Element; + Element = (TabbedPage)element; + + if (oldElement != null) + { + oldElement.PropertyChanged -= OnElementPropertyChanged; + ((INotifyCollectionChanged)oldElement.Children).CollectionChanged -= OnPagesChanged; + } + + if (element != null) + { + if (Control == null) + { + Control = new FormsPivot + { + Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["TabbedPageStyle"], + }; + + Control.SelectionChanged += OnSelectionChanged; + + Tracker = new BackgroundTracker<Pivot>(Windows.UI.Xaml.Controls.Control.BackgroundProperty) + { + Element = (Page)element, + Control = Control, + Container = Control + }; + + Control.Loaded += OnLoaded; + Control.Unloaded += OnUnloaded; + } + + Control.DataContext = Element; + OnPagesChanged(Element.Children, + new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); + + UpdateCurrentPage(); + UpdateToolbarPlacement(); + + ((INotifyCollectionChanged)Element.Children).CollectionChanged += OnPagesChanged; + element.PropertyChanged += OnElementPropertyChanged; + + if (!string.IsNullOrEmpty(element.AutomationId)) + Control.SetValue(AutomationProperties.AutomationIdProperty, element.AutomationId); + } + + OnElementChanged(new VisualElementChangedEventArgs(oldElement, element)); + } + + protected virtual void Dispose(bool disposing) + { + if (!disposing || _disposed) + return; + + _disposed = true; + PageController?.SendDisappearing(); + SetElement(null); + Tracker = null; + } + + protected virtual void OnElementChanged(VisualElementChangedEventArgs e) + { + EventHandler<VisualElementChangedEventArgs> changed = ElementChanged; + if (changed != null) + changed(this, e); + } + + 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(); + else if (e.PropertyName == PlatformConfiguration.WindowsSpecific.Page.ToolbarPlacementProperty.PropertyName) + UpdateToolbarPlacement(); + } + + void OnLoaded(object sender, RoutedEventArgs args) + { + PageController?.SendAppearing(); + UpdateBarTextColor(); + UpdateBarBackgroundColor(); + } + + void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e) + { + e.Apply(Element.Children, Control.Items); + + // Potential performance issue, UpdateLayout () is called for every page change + Control.UpdateLayout(); + } + + void OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + if (Element == null) + return; + + Page page = e.AddedItems.Count > 0 ? (Page)e.AddedItems[0] : null; + Page currentPage = Element.CurrentPage; + if (currentPage == page) + return; + ((IPageController)currentPage)?.SendDisappearing(); + Element.CurrentPage = page; + ((IPageController)page)?.SendAppearing(); + } + + void OnUnloaded(object sender, RoutedEventArgs args) + { + PageController?.SendDisappearing(); + } + + Brush GetBarBackgroundBrush() + { + object defaultColor = + Windows.UI.Xaml.Application.Current.Resources["SystemControlBackgroundChromeMediumLowBrush"]; + if (Element.BarBackgroundColor.IsDefault && defaultColor != null) + return (Brush)defaultColor; + return Element.BarBackgroundColor.ToBrush(); + } + + Brush GetBarForegroundBrush() + { + object defaultColor = Windows.UI.Xaml.Application.Current.Resources["ApplicationForegroundThemeBrush"]; + if (Element.BarTextColor.IsDefault && defaultColor != null) + return (Brush)defaultColor; + return Element.BarTextColor.ToBrush(); + } + + void UpdateBarBackgroundColor() + { + 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() + { + 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 UpdateTitleVisibility() + { + Control.TitleVisibility = _showTitle ? Visibility.Visible : Visibility.Collapsed; + } + + void UpdateCurrentPage() + { + Page page = Element.CurrentPage; + + var nav = page as NavigationPage; + TitleProvider.ShowTitle = nav != null; + + if (page == null) + return; + + Control.SelectedItem = page; + } + + void UpdateToolbarPlacement() + { + Control.ToolbarPlacement = Element.OnThisPlatform().GetToolbarPlacement(); + } + } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.UAP/TabbedPageStyle.xaml b/Xamarin.Forms.Platform.UAP/TabbedPageStyle.xaml new file mode 100644 index 00000000..6d54a073 --- /dev/null +++ b/Xamarin.Forms.Platform.UAP/TabbedPageStyle.xaml @@ -0,0 +1,199 @@ +<ResourceDictionary + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:uwp="using:Xamarin.Forms.Platform.UWP"> + <Style x:Key="TabbedPageStyle" TargetType="uwp:FormsPivot"> + <Setter Property="HeaderTemplate"> + <Setter.Value> + <DataTemplate> + <TextBlock Name="TabbedPageHeaderTextBlock" Text="{Binding Title}" Style="{ThemeResource BodyTextBlockStyle}" /> + </DataTemplate> + </Setter.Value> + </Setter> + + <Setter Property="ItemTemplate"> + <Setter.Value> + <DataTemplate> + <uwp:TabbedPagePresenter Content="{Binding}" ContentTemplate="{ThemeResource ContainedPageTemplate}" /> + </DataTemplate> + </Setter.Value> + </Setter> + + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="uwp:FormsPivot"> + <Grid x:Name="RootElement" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}"> + + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition Height="*"/> + <RowDefinition Height="Auto"/> + </Grid.RowDefinitions> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="NavigationButtonsVisibility"> + <VisualState x:Name="NavigationButtonsHidden"/> + <VisualState x:Name="NavigationButtonsVisible"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="NextButton"> + <DiscreteObjectKeyFrame KeyTime="0" Value="1"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsEnabled" Storyboard.TargetName="NextButton"> + <DiscreteObjectKeyFrame KeyTime="0" Value="True"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PreviousButton"> + <DiscreteObjectKeyFrame KeyTime="0" Value="1"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsEnabled" Storyboard.TargetName="PreviousButton"> + <DiscreteObjectKeyFrame KeyTime="0" Value="True"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + </VisualStateGroup> + <VisualStateGroup x:Name="HeaderStates"> + <VisualState x:Name="HeaderDynamic"/> + <VisualState x:Name="HeaderStatic"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="Header"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="StaticHeader"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + + <Grid x:Name="TitleBar" Background="{TemplateBinding ToolbarBackground}" HorizontalAlignment="Stretch"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="Auto"></ColumnDefinition> + <ColumnDefinition Width="*"></ColumnDefinition> + </Grid.ColumnDefinitions> + + <Border Height="{ThemeResource TitleBarHeight}" Visibility="{TemplateBinding TitleVisibility}"> + <TextBlock Text="{Binding Title}" VerticalAlignment="Center" Padding="10,0,0,0" Foreground="{TemplateBinding ToolbarForeground}" Style="{ThemeResource TitleTextBlockStyle}" /> + </Border> + + <Border x:Name="TopCommandBarArea" Grid.Column="1" HorizontalAlignment="Stretch"> + <uwp:FormsCommandBar x:Name="CommandBar" VerticalContentAlignment="Top" Background="{TemplateBinding ToolbarBackground}" Height="{ThemeResource TitleBarHeight}" /> + </Border> + </Grid> + + <Grid Grid.Row="1"> + <Grid.Resources> + <ControlTemplate x:Key="NextTemplate" TargetType="Button"> + <Border x:Name="Root" BorderBrush="{ThemeResource SystemControlForegroundTransparentBrush}" BorderThickness="{ThemeResource PivotNavButtonBorderThemeThickness}" Background="{ThemeResource SystemControlBackgroundBaseMediumLowBrush}"> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualState x:Name="Normal"/> + <VisualState x:Name="PointerOver"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Root"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseMediumBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="Arrow"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltAltMediumHighBrush}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Pressed"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Root"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseMediumHighBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="Arrow"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltAltMediumHighBrush}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <FontIcon x:Name="Arrow" Foreground="{ThemeResource SystemControlForegroundAltMediumHighBrush}" FontSize="12" FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="" HorizontalAlignment="Center" MirroredWhenRightToLeft="True" UseLayoutRounding="False" VerticalAlignment="Center"/> + </Border> + </ControlTemplate> + <ControlTemplate x:Key="PreviousTemplate" TargetType="Button"> + <Border x:Name="Root" BorderBrush="{ThemeResource SystemControlForegroundTransparentBrush}" BorderThickness="{ThemeResource PivotNavButtonBorderThemeThickness}" Background="{ThemeResource SystemControlBackgroundBaseMediumLowBrush}"> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualState x:Name="Normal"/> + <VisualState x:Name="PointerOver"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Root"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseMediumBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="Arrow"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltAltMediumHighBrush}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Pressed"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Root"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseMediumHighBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="Arrow"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltAltMediumHighBrush}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <FontIcon x:Name="Arrow" Foreground="{ThemeResource SystemControlForegroundAltMediumHighBrush}" FontSize="12" FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="" HorizontalAlignment="Center" MirroredWhenRightToLeft="True" UseLayoutRounding="False" VerticalAlignment="Center"/> + </Border> + </ControlTemplate> + </Grid.Resources> + <ScrollViewer x:Name="ScrollViewer" BringIntoViewOnFocusChange="False" HorizontalSnapPointsAlignment="Center" HorizontalSnapPointsType="MandatorySingle" HorizontalScrollBarVisibility="Hidden" Margin="{TemplateBinding Padding}" Template="{StaticResource ScrollViewerScrollBarlessTemplate}" VerticalSnapPointsType="None" VerticalScrollBarVisibility="Disabled" VerticalScrollMode="Disabled" VerticalContentAlignment="Stretch" ZoomMode="Disabled"> + <PivotPanel x:Name="Panel" VerticalAlignment="Stretch"> + <Grid x:Name="PivotLayoutElement"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="Auto"/> + <ColumnDefinition Width="*"/> + <ColumnDefinition Width="Auto"/> + </Grid.ColumnDefinitions> + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition Height="*"/> + </Grid.RowDefinitions> + <Grid.RenderTransform> + <CompositeTransform x:Name="PivotLayoutElementTranslateTransform"/> + </Grid.RenderTransform> + <ContentPresenter x:Name="LeftHeaderPresenter" ContentTemplate="{TemplateBinding LeftHeaderTemplate}" Content="{TemplateBinding LeftHeader}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> + <ContentControl x:Name="HeaderClipper" Grid.Column="1" HorizontalContentAlignment="Stretch" UseSystemFocusVisuals="True"> + <ContentControl.Clip> + <RectangleGeometry x:Name="HeaderClipperGeometry"/> + </ContentControl.Clip> + <Grid Name="TabbedPageHeaderGrid" Background="{TemplateBinding ToolbarBackground}"> + <PivotHeaderPanel x:Name="StaticHeader" Visibility="Collapsed"/> + <PivotHeaderPanel x:Name="Header"> + <PivotHeaderPanel.RenderTransform> + <TransformGroup> + <CompositeTransform x:Name="HeaderTranslateTransform"/> + <CompositeTransform x:Name="HeaderOffsetTranslateTransform"/> + </TransformGroup> + </PivotHeaderPanel.RenderTransform> + </PivotHeaderPanel> + </Grid> + </ContentControl> + <Button x:Name="PreviousButton" Background="Transparent" Grid.Column="1" HorizontalAlignment="Left" Height="36" IsTabStop="False" IsEnabled="False" Margin="{ThemeResource PivotNavButtonMargin}" Opacity="0" Template="{StaticResource PreviousTemplate}" UseSystemFocusVisuals="False" VerticalAlignment="Top" Width="20"/> + <Button x:Name="NextButton" Background="Transparent" Grid.Column="1" HorizontalAlignment="Right" Height="36" IsTabStop="False" IsEnabled="False" Margin="{ThemeResource PivotNavButtonMargin}" Opacity="0" Template="{StaticResource NextTemplate}" UseSystemFocusVisuals="False" VerticalAlignment="Top" Width="20"/> + <ContentPresenter x:Name="RightHeaderPresenter" ContentTemplate="{TemplateBinding RightHeaderTemplate}" Content="{TemplateBinding RightHeader}" Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> + <ItemsPresenter x:Name="PivotItemPresenter" Grid.ColumnSpan="3" Grid.Row="1"> + <ItemsPresenter.RenderTransform> + <TransformGroup> + <TranslateTransform x:Name="ItemsPresenterTranslateTransform"/> + <CompositeTransform x:Name="ItemsPresenterCompositeTransform"/> + </TransformGroup> + </ItemsPresenter.RenderTransform> + </ItemsPresenter> + </Grid> + </PivotPanel> + </ScrollViewer> + </Grid> + + <Border x:Name="BottomCommandBarArea" Grid.Row="2" HorizontalAlignment="Stretch"></Border> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> +</ResourceDictionary>
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.UAP/ToolbarPlacementHelper.cs b/Xamarin.Forms.Platform.UAP/ToolbarPlacementHelper.cs new file mode 100644 index 00000000..24feecbc --- /dev/null +++ b/Xamarin.Forms.Platform.UAP/ToolbarPlacementHelper.cs @@ -0,0 +1,46 @@ +using Windows.UI.Xaml.Controls; +using Xamarin.Forms.PlatformConfiguration.WindowsSpecific; + +namespace Xamarin.Forms.Platform.UWP +{ + internal class ToolbarPlacementHelper + { + public static void UpdateToolbarPlacement(CommandBar toolbar, ToolbarPlacement toolbarPlacement, Border bottomCommandBarArea, Border topCommandBarArea) + { + if (toolbar == null || bottomCommandBarArea == null || topCommandBarArea == null) + { + // Haven't applied the template yet, so we're not ready to do this + return; + } + + // Figure out what's hosting the command bar right now + var current = toolbar.Parent as Border; + + // And figure out where it should be + Border target; + + switch (toolbarPlacement) + { + case ToolbarPlacement.Top: + target = topCommandBarArea; + break; + case ToolbarPlacement.Bottom: + target = bottomCommandBarArea; + break; + case ToolbarPlacement.Default: + default: + target = Device.Idiom == TargetIdiom.Phone ? bottomCommandBarArea : topCommandBarArea; + break; + } + + if (current == null || target == null || current == target) + { + return; + } + + // Remove the command bar from its current host and add it to the new one + current.Child = null; + target.Child = toolbar; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj b/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj index 4e804819..ce1b1066 100644 --- a/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj +++ b/Xamarin.Forms.Platform.UAP/Xamarin.Forms.Platform.UAP.csproj @@ -164,6 +164,9 @@ <Compile Include="..\Xamarin.Forms.Platform.WinRT\NativeViewWrapperRenderer.cs"> <Link>NativeViewWrapperRenderer.cs</Link> </Compile> + <Compile Include="..\Xamarin.Forms.Platform.WinRT\PlatformConfigurationExtensions.cs"> + <Link>PlatformConfigurationExtensions.cs</Link> + </Compile> <Compile Include="..\Xamarin.Forms.Platform.WinRT\PlatformEffect.cs"> <Link>PlatformEffect.cs</Link> </Compile> @@ -183,6 +186,7 @@ </Compile> <Compile Include="StepperControl.cs" /> <Compile Include="TabbedPageRenderer.cs" /> + <Compile Include="ToolbarPlacementHelper.cs" /> <Content Include="Properties\Xamarin.Forms.Platform.UAP.rd.xml" /> <Compile Include="..\Xamarin.Forms.Core\Properties\GlobalAssemblyInfo.cs"> <Link>Properties\GlobalAssemblyInfo.cs</Link> @@ -432,14 +436,26 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="MasterDetailControlStyle.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="PageControl.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="PageControlStyle.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="Resources.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </Page> + <Page Include="TabbedPageStyle.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> </ItemGroup> <ItemGroup> <ProjectReference Include="..\Xamarin.Forms.Core\Xamarin.Forms.Core.csproj"> |