public static IsGreaterThan ( double left, double right ) : bool | ||
left | double | First number. |
right | double | Second number. |
Résultat | bool |
/// <summary> /// Handle keys related to scrolling. /// </summary> /// <param name="key">The key to handle.</param> /// <returns>A value indicating whether the key was handled.</returns> private bool HandleScrollKeys(Key key) { ScrollViewer scrollHost = ItemsControlHelper.ScrollHost; if (scrollHost != null) { switch (key) { case Key.PageUp: // Move horizontally if we've run out of room vertically if (!NumericExtensions.IsGreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight)) { scrollHost.PageLeft(); } else { scrollHost.PageUp(); } return(true); case Key.PageDown: // Move horizontally if we've run out of room vertically if (!NumericExtensions.IsGreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight)) { scrollHost.PageRight(); } else { scrollHost.PageDown(); } return(true); case Key.Home: scrollHost.ScrollToTop(); return(true); case Key.End: scrollHost.ScrollToBottom(); return(true); case Key.Left: scrollHost.LineLeft(); return(true); case Key.Right: scrollHost.LineRight(); return(true); case Key.Up: scrollHost.LineUp(); return(true); case Key.Down: scrollHost.LineDown(); return(true); } } return(false); }
private bool HandleScrollByPage(bool up) { // NOTE: This implementation assumes that items are laid out // vertically and the Headers of the TreeViewItems appear above // their ItemsPresenter. The same assumptions are made in WPF. ScrollViewer scrollHost = ItemsControlHelper.ScrollHost; if (scrollHost != null) { double viewportHeight = scrollHost.ViewportHeight; double top; double bottom; (SelectedContainer.HeaderElement ?? SelectedContainer).GetTopAndBottom(scrollHost, out top, out bottom); TreeViewItem selected = null; TreeViewItem next = SelectedContainer; ItemsControl parent = SelectedContainer.ParentItemsControl; if (parent != null) { // We need to start at the root TreeViewItem if we're // scrolling up, but can start at the SelectedItem if // scrolling down. if (up) { while (parent != this) { TreeViewItem parentItem = parent as TreeViewItem; if (parentItem == null) { break; } ItemsControl grandparent = parentItem.ParentItemsControl; if (grandparent == null) { break; } next = parentItem; parent = grandparent; } } int index = parent.ItemContainerGenerator.IndexFromContainer(next); int count = parent.Items.Count; while (parent != null && next != null) { if (next.IsEnabled) { double delta; if (next.HandleScrollByPage(up, scrollHost, viewportHeight, top, bottom, out delta)) { // This item or one of its children was focused return(true); } else if (NumericExtensions.IsGreaterThan(delta, viewportHeight)) { // If the item doesn't fit on the page but it's // already selected, we'll select the next item // even though it doesn't completely fit into // the current view if (selected == SelectedContainer || selected == null) { return(up ? SelectedContainer.HandleUpKey() : SelectedContainer.HandleDownKey()); } break; } else { selected = next; } } index += up ? -1 : 1; if (0 <= index && index < count) { next = parent.ItemContainerGenerator.ContainerFromIndex(index) as TreeViewItem; } else if (parent == this) { // We just finished with the last item in the // TreeView next = null; } else { // Move up the parent chain to the next item while (parent != null) { TreeViewItem oldParent = parent as TreeViewItem; parent = oldParent.ParentItemsControl; if (parent != null) { count = parent.Items.Count; index = parent.ItemContainerGenerator.IndexFromContainer(oldParent) + (up ? -1 : 1); if (0 <= index && index < count) { next = parent.ItemContainerGenerator.ContainerFromIndex(index) as TreeViewItem; break; } else if (parent == this) { next = null; parent = null; } } } } } } if (selected != null) { if (up) { if (selected != SelectedContainer) { return(selected.Focus()); } } else { selected.FocusInto(); } } } return(false); }