public static BlockNavigatorInternal CreateNavigator(FrameworkElement element) { var nav = new BlockNavigatorInternal(element); BlockNavigatorProperty.SetBlockNavigator(element, nav); return(nav); }
public static FrameworkElement FindBlockNavigatorElement(FrameworkElement elm) { var searchElm = elm; DependencyObject GetParent(FrameworkElement child) { return(child.Parent ?? child.TemplatedParent ?? System.Windows.Media.VisualTreeHelper.GetParent(child)); } // if we query the navigator on a nested element, make sure we get the parent navigator and not the self if (BlockNavigatorProperty.GetIsNestedNavigation(searchElm) && GetParent(searchElm) != null) { searchElm = (FrameworkElement)GetParent(searchElm); } while (true) { var parent = GetParent(searchElm); if (parent == null) { return(searchElm); } var isNestedNavigator = BlockNavigatorProperty.GetIsNestedNavigation(searchElm); if (isNestedNavigator) { return(searchElm); } searchElm = (FrameworkElement)parent; } }
public void ActivateNestedNavigator(FrameworkElement focusElm) { IsEnabled = false; var nav = BlockNavigatorProperty.GetBlockNavigator(focusElm); nav.ParentNavigator = this; nav.IsEnabled = true; OwnerElement.RaiseEvent(new RoutedEventArgs(BlockNavigatorProperty.NavigationExitEvent, OwnerElement)); nav.OwnerElement.RaiseEvent(new RoutedEventArgs(BlockNavigatorProperty.NavigationEnterEvent, nav.OwnerElement)); }
public static void OnDisableBlockNavigatorChanged(FrameworkElement a, bool value) { var nav = BlockNavigatorProperty.GetBlockNavigator(a); if (nav == null) { var elm = FindBlockNavigatorElement(a); nav = BlockNavigatorProperty.GetBlockNavigator(elm); } nav.IsEnabled = !value; nav.ExplicitDisabled = value; }
public static void RegisterNestedNavigationBlock(FrameworkElement frameworkElement) { // register on parent navigator that is RegisterNavigationBlock(frameworkElement); var navigator = BlockNavigatorProperty.GetBlockNavigator(frameworkElement); if (navigator == null) { navigator = CreateNavigator(frameworkElement); navigator.IsEnabled = false; } var parentNavigator = FindBlockNavigatorElement(frameworkElement); navigator.ParentNavigator = BlockNavigatorProperty.GetBlockNavigator(parentNavigator); }
public static void RegisterNavigationBlock(FrameworkElement frameworkElement) { var parentElement = FindBlockNavigatorElement(frameworkElement); var nav = BlockNavigatorProperty.GetBlockNavigator(parentElement); if (nav == null) { nav = CreateNavigator(parentElement); nav.IsEnabled = true; } // bugfix: The control will not be part of the correct hierarchy until it's fully loaded frameworkElement.Loaded += delegate { nav.OnAddBlock(frameworkElement); }; }
private void OnFocusChanged(FrameworkElement elm, bool animate = true) { _focusElement?.Dispatcher.Invoke(() => { BlockNavigatorProperty.SetIsFocused(_focusElement, false); _focusElement?.RaiseEvent(new RoutedEventArgs(BlockNavigatorProperty.CursorExitEvent, _focusElement)); }); elm.Dispatcher.Invoke(() => { _focusElement = elm; BlockNavigatorProperty.SetIsFocused(_focusElement, true); _focusElement.RaiseEvent(new RoutedEventArgs(BlockNavigatorProperty.CursorEnterEvent, _focusElement)); _cursor.SetFocus(_blocks[_focusElement], animate); _cursor.Visibility = BlockNavigatorProperty.GetHideCursor(_focusElement) || IsEnabled == false ? Visibility.Hidden : Visibility.Visible; }); }
private void OnConfirmClick(int player, GamePadState state) { _focusElement?.Dispatcher.Invoke(() => { OwnerElement?.RaiseEvent(new RoutedEventArgs(BlockNavigatorProperty.ConfirmClickEvent, OwnerElement)); _focusElement?.RaiseEvent(new RoutedEventArgs(BlockNavigatorProperty.ConfirmClickEvent, _focusElement)); if (BlockNavigatorProperty.GetSimulateMouse(_focusElement)) { SimulateMouse(_focusElement); } if (BlockNavigatorProperty.GetIsNestedNavigation(_focusElement)) { ActivateNestedNavigator(_focusElement); } }); }
private void SetInitialFocus(FrameworkElement elm) { var initialFocus = BlockNavigatorProperty.GetInitialFocus(elm); if (initialFocus) { _focusElement = elm; _hasManualFocus = true; OnFocusChanged(elm, false); } else if (_hasManualFocus == false && _focusElement == null) { _focusElement = elm; OnFocusChanged(elm, false); } }
public static void OnFocusableChanged(FrameworkElement a, bool value) { void f(FrameworkElement p) { var parent = FindBlockNavigatorElement(a); if (parent == a) { parent = FindBlockNavigatorElement((FrameworkElement)a.Parent); } var nav = BlockNavigatorProperty.GetBlockNavigator(parent); if (value == false) { nav._blocks.Remove(a); } else { var point = a .TransformToAncestor(parent) .Transform(new Point(0, 0)); nav._blocks[a] = new Rect( point.X, point.Y, a.ActualWidth, a.ActualHeight ); } } if (a.IsLoaded) { f(a); } else { new Await(a, f).Loaded(); } }