public static bool OnNavigateChildren(this IPopupItem item) { if (!item.HasItems()) { return(false); } item.PopupRoot.PopupManager.OpenedItem = item; item.PopupChildren().SelectableItem().FirstOrDefault().NavigateItem(); return(true); }
public static void OnKeyDownNavigate(this IPopupItem item, KeyEventArgs e) { if (!item.Handle(e)) { return; } var key = e.Key; var fe = item as FrameworkElement; if (fe != null) { if (fe.FlowDirection == FlowDirection.RightToLeft) { switch (key) { case Key.Right: key = Key.Left; break; case Key.Left: key = Key.Right; break; } } } var pm = item.PopupRoot.PopupManager; bool isRoot = item.ParentItem() == null; var top = item; while (top.ParentItem() != null) { top = top.ParentItem(); } if (key == Key.Tab) { bool shift = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift; if (isRoot) { key = shift ? Key.Left : Key.Right; } else { key = shift ? Key.Up : Key.Down; } } switch (key) { case Key.Escape: if (isRoot) { Keyboard.Focus(null); e.Handled = true; } else { e.Handled = null != item.ParentItem().NavigateItem(false); } break; case Key.Right: if (isRoot) { e.Handled = null != item.NavigateSibling(true, true); } else { if (item.HasItems()) { item.OnNavigateChildren(); e.Handled = true; } else { pm.OpenedItem = top.NavigateSibling(true, true); e.Handled = null != pm.OpenedItem; } } break; case Key.Left: if (isRoot) { e.Handled = null != item.NavigateSibling(false, true); } else { if (item.ParentItem() != top) { e.Handled = null != item.ParentItem().NavigateItem(); } else { pm.OpenedItem = top.NavigateSibling(false, true); e.Handled = null != pm.OpenedItem; } } break; case Key.Up: if (isRoot) { e.Handled = item.OnNavigateChildren(); } else { e.Handled = null != item.NavigateSibling(false, true); } break; case Key.Down: if (isRoot) { e.Handled = item.OnNavigateChildren(); } else { e.Handled = null != item.NavigateSibling(true, true); } break; case Key.Enter: case Key.Space: e.Handled = true; item.IsPressed = true; break; } }