diff options
Diffstat (limited to 'Xamarin.Forms.Platform.UAP/MasterDetailControl.cs')
-rw-r--r-- | Xamarin.Forms.Platform.UAP/MasterDetailControl.cs | 100 |
1 files changed, 92 insertions, 8 deletions
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 |