summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.UAP/ToolbarPlacementHelper.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.UAP/ToolbarPlacementHelper.cs')
-rw-r--r--Xamarin.Forms.Platform.UAP/ToolbarPlacementHelper.cs56
1 files changed, 52 insertions, 4 deletions
diff --git a/Xamarin.Forms.Platform.UAP/ToolbarPlacementHelper.cs b/Xamarin.Forms.Platform.UAP/ToolbarPlacementHelper.cs
index 24feecbc..1b36010a 100644
--- a/Xamarin.Forms.Platform.UAP/ToolbarPlacementHelper.cs
+++ b/Xamarin.Forms.Platform.UAP/ToolbarPlacementHelper.cs
@@ -1,18 +1,50 @@
-using Windows.UI.Xaml.Controls;
+using System;
+using Windows.UI.Xaml;
+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)
+ Border _bottomCommandBarArea;
+ CommandBar _commandBar;
+ Func<ToolbarPlacement> _getToolbarPlacement;
+ Border _titleArea;
+ Border _topCommandBarArea;
+
+ public void Initialize(CommandBar commandBar, Func<ToolbarPlacement> getToolbarPlacement,
+ Func<string, DependencyObject> getTemplateChild)
+ {
+ _commandBar = commandBar;
+ _getToolbarPlacement = getToolbarPlacement;
+ _bottomCommandBarArea = getTemplateChild("BottomCommandBarArea") as Border;
+ _topCommandBarArea = getTemplateChild("TopCommandBarArea") as Border;
+ _titleArea = getTemplateChild("TitleArea") as Border;
+
+ if (_commandBar != null && _bottomCommandBarArea != null && _topCommandBarArea != null)
+ {
+ // We have to wait for the command bar to load so that it'll be in the control hierarchy
+ // otherwise we can't properly move it to wherever the toolbar is supposed to be
+ _commandBar.Loaded += (sender, args) => UpdateToolbarPlacement();
+ }
+ }
+
+ public void UpdateToolbarPlacement()
{
- if (toolbar == null || bottomCommandBarArea == null || topCommandBarArea == null)
+ if (_commandBar == null || _getToolbarPlacement == null || _bottomCommandBarArea == null ||
+ _topCommandBarArea == null)
{
- // Haven't applied the template yet, so we're not ready to do this
+ // Template hasn't been applied yet, so we're not ready to update the toolbar placement
return;
}
+ UpdateToolbarPlacement(_commandBar, _getToolbarPlacement(), _bottomCommandBarArea, _topCommandBarArea, _titleArea);
+ }
+
+ static void UpdateToolbarPlacement(CommandBar toolbar, ToolbarPlacement toolbarPlacement, Border bottomCommandBarArea,
+ Border topCommandBarArea, Border titleArea)
+ {
// Figure out what's hosting the command bar right now
var current = toolbar.Parent as Border;
@@ -41,6 +73,22 @@ namespace Xamarin.Forms.Platform.UWP
// Remove the command bar from its current host and add it to the new one
current.Child = null;
target.Child = toolbar;
+
+ if (titleArea != null)
+ {
+ if (target == bottomCommandBarArea)
+ {
+ // If the title is hosted in the command bar and we're moving the command bar to the bottom,
+ // put the title into the topCommandBarArea
+ toolbar.Content = null;
+ topCommandBarArea.Child = titleArea;
+ }
+ else
+ {
+ // Put the title back into the command bar
+ toolbar.Content = titleArea;
+ }
+ }
}
}
} \ No newline at end of file