diff --git a/Screenbox/Controls/CustomNavigationView.cs b/Screenbox/Controls/CustomNavigationView.cs deleted file mode 100644 index 16bafd21a..000000000 --- a/Screenbox/Controls/CustomNavigationView.cs +++ /dev/null @@ -1,207 +0,0 @@ -#nullable enable - -using CommunityToolkit.WinUI; -using CommunityToolkit.WinUI.Animations; -using System; -using System.Numerics; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Input; -using NavigationView = Microsoft.UI.Xaml.Controls.NavigationView; -using NavigationViewDisplayMode = Microsoft.UI.Xaml.Controls.NavigationViewDisplayMode; - -namespace Screenbox.Controls -{ - public sealed class CustomNavigationView : NavigationView - { - public static readonly DependencyProperty OverlayContentProperty = DependencyProperty.Register( - nameof(OverlayContent), - typeof(UIElement), - typeof(CustomNavigationView), - new PropertyMetadata(null, OnOverlayContentChanged)); - - public static readonly DependencyProperty OverlayZIndexProperty = DependencyProperty.Register( - nameof(OverlayZIndex), - typeof(int), - typeof(CustomNavigationView), - new PropertyMetadata(0, OnOverlayZIndexChanged)); - - public static readonly DependencyProperty ContentVisibilityProperty = DependencyProperty.Register( - nameof(ContentVisibility), - typeof(Visibility), - typeof(CustomNavigationView), - new PropertyMetadata(Visibility.Visible, OnContentVisibilityChanged)); - - /// - /// Visibility of everything except the overlay element. - /// - public Visibility ContentVisibility - { - get => (Visibility)GetValue(ContentVisibilityProperty); - set => SetValue(ContentVisibilityProperty, value); - } - - /// - /// Canvas.ZIndex of the overlay element. Set a value above 1 to render on top of the nav pane. Default is 0. - /// - public int OverlayZIndex - { - get => (int)GetValue(OverlayZIndexProperty); - set => SetValue(OverlayZIndexProperty, value); - } - - /// - /// Content of the overlay element that has the same level with the nav pane. - /// - public UIElement? OverlayContent - { - get => (UIElement?)GetValue(OverlayContentProperty); - set => SetValue(OverlayContentProperty, value); - } - - private readonly Border _overlayRoot; - private Border? _contentBackground; - private SplitView? _splitView; - private Grid? _paneToggleButtonGrid; - private Grid? _contentGrid; - private Grid? _paneContentGrid; - - public CustomNavigationView() - { - Loaded += OnLoaded; - - Border overlayRoot = new() - { - Name = "OverlayRoot" - }; - overlayRoot.Tapped += OverlayRootOnTapped; - overlayRoot.SetValue(Grid.ColumnProperty, 0); - overlayRoot.SetValue(Grid.ColumnSpanProperty, 2); - _overlayRoot = overlayRoot; - } - - protected override void OnApplyTemplate() - { - base.OnApplyTemplate(); - _splitView = (SplitView?)GetTemplateChild("RootSplitView"); - _paneToggleButtonGrid = (Grid?)GetTemplateChild("PaneToggleButtonGrid"); - _contentGrid = (Grid?)GetTemplateChild("ContentGrid"); - _paneContentGrid = (Grid?)GetTemplateChild("PaneContentGrid"); - Grid? shadowCaster = (Grid?)GetTemplateChild("ShadowCaster"); - if (shadowCaster != null) - { - shadowCaster.Translation = new Vector3(0, 0, 32); - } - - SetContentVisibility(ContentVisibility); - - // Set implicit animations to play when ContentVisibility changes - _paneToggleButtonGrid?.SetValue(Implicit.ShowAnimationsProperty, GetShowAnimations()); - _paneToggleButtonGrid?.SetValue(Implicit.HideAnimationsProperty, GetHideAnimations()); - _contentGrid?.SetValue(Implicit.ShowAnimationsProperty, GetShowAnimations()); - _contentGrid?.SetValue(Implicit.HideAnimationsProperty, GetHideAnimations()); - - // Don't set implicit animations on _paneContentGrid because of conflict with base NavView - // _paneContentGrid?.SetValue(Implicit.ShowAnimationsProperty, GetShowAnimations()); - // _paneContentGrid?.SetValue(Implicit.HideAnimationsProperty, GetHideAnimations()); - } - - protected override void OnKeyDown(KeyRoutedEventArgs e) - { - if (ContentVisibility == Visibility.Visible) - { - base.OnKeyDown(e); - } - } - - private void OnLoaded(object sender, RoutedEventArgs e) - { - if (_splitView?.FindDescendant() is { } splitViewGrid) - { - splitViewGrid.Children.Add(_overlayRoot); - } - - if (_splitView?.FindDescendant(b => b.Name == "ContentBackground") is { } contentBackground) - { - _contentBackground = contentBackground; - contentBackground.SetValue(Implicit.ShowAnimationsProperty, GetShowAnimations()); - contentBackground.SetValue(Implicit.HideAnimationsProperty, GetHideAnimations()); - } - } - - private void OverlayRootOnTapped(object sender, TappedRoutedEventArgs e) - { - if (DisplayMode != NavigationViewDisplayMode.Expanded && IsPaneOpen) - { - IsPaneOpen = false; - } - } - - private void SetContentVisibility(Visibility visibility) - { - if (_paneToggleButtonGrid != null) - { - _paneToggleButtonGrid.Visibility = visibility; - } - - if (_contentGrid != null) - { - _contentGrid.Visibility = visibility; - } - - if (_paneContentGrid != null) - { - _paneContentGrid.Visibility = visibility; - } - - if (_contentBackground != null) - { - _contentBackground.Visibility = visibility; - } - } - - private static void OnContentVisibilityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - CustomNavigationView view = (CustomNavigationView)d; - view.SetContentVisibility((Visibility)e.NewValue); - } - - private static void OnOverlayContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - CustomNavigationView view = (CustomNavigationView)d; - view._overlayRoot.Child = (UIElement)e.NewValue; - } - - private static void OnOverlayZIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - CustomNavigationView view = (CustomNavigationView)d; - Canvas.SetZIndex(view._overlayRoot, (int)e.NewValue); - } - - private static ImplicitAnimationSet GetShowAnimations() - { - return new ImplicitAnimationSet - { - new OpacityAnimation - { - Duration = TimeSpan.FromSeconds(0.3), - From = 0, - To = 1 - } - }; - } - - private static ImplicitAnimationSet GetHideAnimations() - { - return new ImplicitAnimationSet - { - new OpacityAnimation - { - Duration = TimeSpan.FromSeconds(0.3), - From = 1, - To = 0 - } - }; - } - } -} diff --git a/Screenbox/Controls/Interactions/NavigationViewKeyboardBehavior.cs b/Screenbox/Controls/Interactions/NavigationViewKeyboardBehavior.cs deleted file mode 100644 index 690376a66..000000000 --- a/Screenbox/Controls/Interactions/NavigationViewKeyboardBehavior.cs +++ /dev/null @@ -1,239 +0,0 @@ -using CommunityToolkit.WinUI; -using CommunityToolkit.WinUI.Behaviors; -using Windows.System; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Input; - -namespace Screenbox.Controls.Interactions; - -/// -/// A behavior that improves the keyboard interaction of the built-in elements. -/// -internal class NavigationViewKeyboardBehavior : BehaviorBase -{ - ///// - ///// Identifies the dependency property. - ///// - //public static readonly DependencyProperty BackButtonAccessKeyProperty = DependencyProperty.Register( - // nameof(BackButtonAccessKey), typeof(string), typeof(NavigationViewKeyboardBehavior), new PropertyMetadata(null)); - - ///// - ///// Gets or sets the access key of the back button. - ///// - //public string BackButtonAccessKey - //{ - // get => (string)GetValue(BackButtonAccessKeyProperty); - // set => SetValue(BackButtonAccessKeyProperty, value); - //} - - ///// - ///// Identifies the dependency property. - ///// - //public static readonly DependencyProperty BackButtonKeyTipPlacementModeProperty = DependencyProperty.Register( - // nameof(BackButtonKeyTipPlacementMode), typeof(KeyTipPlacementMode), typeof(NavigationViewKeyboardBehavior), new PropertyMetadata(default(KeyTipPlacementMode))); - - ///// - ///// Gets or sets where the key tip is placed in relation to the boundary of the back button. - ///// - //public KeyTipPlacementMode BackButtonKeyTipPlacementMode - //{ - // get => (KeyTipPlacementMode)GetValue(BackButtonKeyTipPlacementModeProperty); - // set => SetValue(BackButtonKeyTipPlacementModeProperty, value); - //} - - ///// - ///// Identifies the dependency property. - ///// - //public static readonly DependencyProperty CloseButtonAccessKeyProperty = DependencyProperty.Register( - // nameof(CloseButtonAccessKey), typeof(string), typeof(NavigationViewKeyboardBehavior), new PropertyMetadata(null)); - - ///// - ///// Gets or sets the access key of the close button. - ///// - //public string CloseButtonAccessKey - //{ - // get => (string)GetValue(CloseButtonAccessKeyProperty); - // set => SetValue(CloseButtonAccessKeyProperty, value); - //} - - ///// - ///// Identifies the dependency property. - ///// - //public static readonly DependencyProperty CloseButtonKeyTipPlacementModeProperty = DependencyProperty.Register( - // nameof(CloseButtonKeyTipPlacementMode), typeof(KeyTipPlacementMode), typeof(NavigationViewKeyboardBehavior), new PropertyMetadata(default(KeyTipPlacementMode))); - - ///// - ///// Gets or sets where the key tip is placed in relation to the boundary of the close button. - ///// - //public KeyTipPlacementMode CloseButtonKeyTipPlacementMode - //{ - // get => (KeyTipPlacementMode)GetValue(CloseButtonKeyTipPlacementModeProperty); - // set => SetValue(CloseButtonKeyTipPlacementModeProperty, value); - //} - - ///// - ///// Identifies the dependency property. - ///// - //public static readonly DependencyProperty TogglePaneButtonAccessKeyProperty = DependencyProperty.Register( - // nameof(TogglePaneButtonAccessKey), typeof(string), typeof(NavigationViewKeyboardBehavior), new PropertyMetadata(null)); - - ///// - ///// Gets or sets the access key of the menu toggle button. - ///// - //public string TogglePaneButtonAccessKey - //{ - // get => (string)GetValue(TogglePaneButtonAccessKeyProperty); - // set => SetValue(TogglePaneButtonAccessKeyProperty, value); - //} - - ///// - ///// Identifies the dependency property. - ///// - //public static readonly DependencyProperty TogglePaneButtonKeyTipPlacementModeProperty = DependencyProperty.Register( - // nameof(TogglePaneButtonKeyTipPlacementMode), typeof(KeyTipPlacementMode), typeof(NavigationViewKeyboardBehavior), new PropertyMetadata(default(KeyTipPlacementMode))); - - ///// - ///// Gets or sets where the key tip is placed in relation to the boundary of the menu toggle button. - ///// - //public KeyTipPlacementMode TogglePaneButtonKeyTipPlacementMode - //{ - // get => (KeyTipPlacementMode)GetValue(TogglePaneButtonKeyTipPlacementModeProperty); - // set => SetValue(TogglePaneButtonKeyTipPlacementModeProperty, value); - //} - - ///// - ///// Identifies the dependency property. - ///// - //public static readonly DependencyProperty TogglePaneButtonKeyboardAcceleratorKeyProperty = DependencyProperty.Register( - // nameof(TogglePaneButtonKeyboardAcceleratorKey), typeof(VirtualKey), typeof(NavigationViewKeyboardBehavior), new PropertyMetadata(null)); - - ///// - ///// Gets or sets the virtual key for the keyboard accelerator of the menu toggle button. - ///// - //public VirtualKey TogglePaneButtonKeyboardAcceleratorKey - //{ - // get => (VirtualKey)GetValue(TogglePaneButtonKeyboardAcceleratorKeyProperty); - // set => SetValue(TogglePaneButtonKeyboardAcceleratorKeyProperty, value); - //} - - ///// - ///// Identifies the dependency property. - ///// - //public static readonly DependencyProperty TogglePaneButtonKeyboardAcceleratorModifiersProperty = DependencyProperty.Register( - // nameof(TogglePaneButtonKeyboardAcceleratorModifiers), typeof(VirtualKeyModifiers), typeof(NavigationViewKeyboardBehavior), new PropertyMetadata(null)); - - ///// - ///// Gets or sets the virtual key to modify another keypress for the keyboard accelerator of the menu toggle button. - ///// - //public VirtualKeyModifiers TogglePaneButtonKeyboardAcceleratorModifiers - //{ - // get => (VirtualKeyModifiers)GetValue(TogglePaneButtonKeyboardAcceleratorModifiersProperty); - // set => SetValue(TogglePaneButtonKeyboardAcceleratorModifiersProperty, value); - //} - - ///// - ///// Identifies the dependency property. - ///// - //public static readonly DependencyProperty PaneAutoSuggestButtonAccessKeyProperty = DependencyProperty.Register( - // nameof(PaneAutoSuggestButtonAccessKey), typeof(string), typeof(NavigationViewKeyboardBehavior), new PropertyMetadata(null)); - - ///// - ///// Gets or sets the access key of the auto-suggest button. - ///// - //public string PaneAutoSuggestButtonAccessKey - //{ - // get => (string)GetValue(PaneAutoSuggestButtonAccessKeyProperty); - // set => SetValue(PaneAutoSuggestButtonAccessKeyProperty, value); - //} - - ///// - ///// Identifies the dependency property. - ///// - //public static readonly DependencyProperty PaneAutoSuggestButtonKeyTipPlacementModeProperty = DependencyProperty.Register( - // nameof(PaneAutoSuggestButtonKeyTipPlacementMode), typeof(KeyTipPlacementMode), typeof(NavigationViewKeyboardBehavior), new PropertyMetadata(default(KeyTipPlacementMode))); - - ///// - ///// Gets or sets where the key tip is placed in relation to the boundary of the auto-suggest button. - ///// - //public KeyTipPlacementMode PaneAutoSuggestButtonKeyTipPlacementMode - //{ - // get => (KeyTipPlacementMode)GetValue(PaneAutoSuggestButtonKeyTipPlacementModeProperty); - // set => SetValue(PaneAutoSuggestButtonKeyTipPlacementModeProperty, value); - //} - - ///// - ///// Identifies the dependency property. - ///// - //public static readonly DependencyProperty PaneAutoSuggestButtonKeyboardAcceleratorKeyProperty = DependencyProperty.Register( - // nameof(PaneAutoSuggestButtonKeyboardAcceleratorKey), typeof(VirtualKey), typeof(NavigationViewKeyboardBehavior), new PropertyMetadata(null)); - - ///// - ///// Gets or sets the virtual key for the keyboard accelerator of the auto-suggest button. - ///// - //public VirtualKey PaneAutoSuggestButtonKeyboardAcceleratorKey - //{ - // get => (VirtualKey)GetValue(PaneAutoSuggestButtonKeyboardAcceleratorKeyProperty); - // set => SetValue(PaneAutoSuggestButtonKeyboardAcceleratorKeyProperty, value); - //} - - ///// - ///// Identifies the dependency property. - ///// - //public static readonly DependencyProperty PaneAutoSuggestButtonKeyboardAcceleratorModifiersProperty = DependencyProperty.Register( - // nameof(PaneAutoSuggestButtonKeyboardAcceleratorModifiers), typeof(VirtualKeyModifiers), typeof(NavigationViewKeyboardBehavior), new PropertyMetadata(null)); - - ///// - ///// Gets or sets the virtual key to modify another keypress for the keyboard accelerator of the auto-suggest button. - ///// - //public VirtualKeyModifiers PaneAutoSuggestButtonKeyboardAcceleratorModifiers - //{ - // get => (VirtualKeyModifiers)GetValue(PaneAutoSuggestButtonKeyboardAcceleratorModifiersProperty); - // set => SetValue(PaneAutoSuggestButtonKeyboardAcceleratorModifiersProperty, value); - //} - - private readonly string _backButtonAccessKey = Strings.KeyboardResources.NavigationBackButtonKey; - private readonly string _closeButtonAccessKey = Strings.KeyboardResources.NavigationCloseButtonKey; - private readonly string _togglePaneButtonAccessKey = Strings.KeyboardResources.NavigationTogglePaneButtonKey; - private readonly string _paneAutoSuggestButtonAccessKey = Strings.KeyboardResources.NavigationPaneAutoSuggestButtonKey; - - private const KeyTipPlacementMode RightAccessKeyPlacement = KeyTipPlacementMode.Right; - private const KeyTipPlacementMode BottomAccessKeyPlacement = KeyTipPlacementMode.Bottom; - - private const VirtualKey TogglePaneKeyboardAcceleratorKey = VirtualKey.E; - private const VirtualKey PaneAutoSuggestKeyboardAcceleratorKey = VirtualKey.F; - private const VirtualKeyModifiers CtrlKeyboardAcceleratorModifier = VirtualKeyModifiers.Control; - - protected override void OnAssociatedObjectLoaded() - { - base.OnAssociatedObjectLoaded(); - - if (AssociatedObject.FindDescendant