Ejemplo n.º 1
0
        protected override void OnAccessKey(swi.AccessKeyEventArgs e)
        {
            // move focus to the next control after the label
            var tRequest = new swi.TraversalRequest(swi.FocusNavigationDirection.Next);

            MoveFocus(tRequest);
        }
        private static void OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                if (GetFocusNext((UIElement)sender))
                {
                    TraversalRequest tRequest = new TraversalRequest(FocusNavigationDirection.Next);
                    UIElement keyboardFocus = Keyboard.FocusedElement as UIElement;

                    if (keyboardFocus != null)
                    {
                        keyboardFocus.MoveFocus(tRequest);
                    }
                }
                else if (GetFocusedControl((UIElement)sender) != null)
                {
                    var ctl = GetFocusedControl((UIElement)sender);
                    if (ctl != null && ctl is IInputElement)
                    {
                        FocusManager.SetFocusedElement(ctl, (IInputElement)ctl);
                    }
                }
                e.Handled = true;
            }
        }
Ejemplo n.º 3
0
		protected override Boolean TabIntoCore(TraversalRequest request)
		{
			if (this.m_GotFocus != null)
			{
				this.m_GotFocus(this, EventArgs.Empty);
			}
			return true;
		}
Ejemplo n.º 4
0
        /// <summary>
        ///     Forwards focus from Avalon and into the WinForms "sink".
        ///     The request is often First and Last, which isn't really mapped the
        ///     same way, but it seems to work, probably because we only host one control.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        internal bool FocusNext(SWI.TraversalRequest request)
        {
            UpdateUIState(NativeMethods.UIS_INITIALIZE);
            bool forward     = true;
            bool tabStopOnly = true;

            switch (request.FocusNavigationDirection)
            {
            case System.Windows.Input.FocusNavigationDirection.Down:
            case System.Windows.Input.FocusNavigationDirection.Right:
                forward     = true;
                tabStopOnly = false;
                break;

            case System.Windows.Input.FocusNavigationDirection.Next:
            case System.Windows.Input.FocusNavigationDirection.First:
                forward     = true;
                tabStopOnly = true;
                break;

            case System.Windows.Input.FocusNavigationDirection.Up:
            case System.Windows.Input.FocusNavigationDirection.Left:
                forward     = false;
                tabStopOnly = false;
                break;

            case System.Windows.Input.FocusNavigationDirection.Previous:
            case System.Windows.Input.FocusNavigationDirection.Last:
                forward     = false;
                tabStopOnly = true;
                break;

            default:
                Debug.Assert(false, "Unknown FocusNavigationDirection");
                break;
            }
            _focusTarget.Enabled = false;
            try
            {
                if (this.SelectNextControl(null, forward, tabStopOnly, true, false))
                {
                    // find the inner most active control
                    ContainerControl ret = this;
                    while (ret.ActiveControl is ContainerControl)
                    {
                        ret = (ContainerControl)ret.ActiveControl;
                    }
                    if (!ret.ContainsFocus)
                    {
                        ret.Focus();
                    }
                    return(true);
                }
                return(false);
            }
            finally
            { _focusTarget.Enabled = true; }
        }
Ejemplo n.º 5
0
 private void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     var row = sender as DataGridRow;
     row.Focusable = true;
     bool focused = row.Focus();
     TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
     UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;
     if (elementWithFocus != null)
         elementWithFocus.MoveFocus(request);
 }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            FocusManager.SetFocusedElement(this, tb);
            TraversalRequest tRequest = new TraversalRequest(FocusNavigationDirection.Next);
            UIElement keyboardFocus = Keyboard.FocusedElement as UIElement;

            if (keyboardFocus != null)
            {
                keyboardFocus.MoveFocus(tRequest);
            }
        }
Ejemplo n.º 7
0
        void KeyUp_TextBox(object sender, KeyEventArgs e)
        {
            var tb = e.OriginalSource as TextBox;
            if (tb == null)
            {
                return;
            }

            if (e.Key == Key.Return || e.Key == Key.Enter)
            {
                var req = new TraversalRequest(FocusNavigationDirection.Next);
                tb.MoveFocus(req);
            }
        }
Ejemplo n.º 8
0
        private void OnMoveFocus(object sender, RoutedEventArgs e)
        {
            // Creating a FocusNavigationDirection object and setting it to a
            // local field that contains the direction selected.
            var focusDirection = _focusMoveValue;

            // MoveFocus takes a TraveralReqest as its argument.
            var request = new TraversalRequest(focusDirection);

            // Gets the element with keyboard focus.
            var elementWithFocus = Keyboard.FocusedElement as UIElement;

            // Change keyboard focus.
            elementWithFocus?.MoveFocus(request);
        }
Ejemplo n.º 9
0
        private static void MoveToNextUIElement(KeyEventArgs e)
        {
            // Creating a FocusNavigationDirection object and setting it to a
            // local field that contains the direction selected.
            const FocusNavigationDirection focusDirection = FocusNavigationDirection.Next;

            // MoveFocus takes a TraveralReqest as its argument.
            var request = new TraversalRequest(focusDirection);

            // Gets the element with keyboard focus.
            var elementWithFocus = Keyboard.FocusedElement as UIElement;

            // Change keyboard focus.
            if (elementWithFocus == null) return;
            if (elementWithFocus.MoveFocus(request)) e.Handled = true;
        }
Ejemplo n.º 10
0
        protected override FrameworkElement CreateDynamicEditingElement(Entity curEntity)
        {
            var value = this.PropertyValue;

            //支持两种属性类型:DateRange,String,所以这里使用这个变量进行分辨
            var useDateRangeType = this.Meta.PropertyMeta.Runtime.PropertyType == typeof(DateRange);

            var range = useDateRangeType ?
                new DateRange(value as DateRange) :
                DateRange.Parse(value != null ? value as string : string.Empty);

            var control = new DateRangePropertyEditorControl(range);
            control.Confirm += (oo, ee) =>
            {
                if (useDateRangeType)
                {
                    var raw = value as DateRange;
                    raw.BeginValue = ee.Range.BeginValue;
                    raw.EndValue = ee.Range.EndValue;
                }
                else
                {
                    this.PropertyValue = ee.Range.ToString();
                }
            };

            control.KeyDown += (oo, ee) =>
            {
                if (ee.Key == Key.Enter)
                {
                    FocusNavigationDirection focusDirection = FocusNavigationDirection.Next;
                    TraversalRequest request = new TraversalRequest(focusDirection);
                    control.MoveFocus(request);
                }
            };

            this.AddReadOnlyComponent(control);

            this.SetAutomationElement(control);

            return control;
        }
Ejemplo n.º 11
0
 void Merlin_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (e.NewValue is QueryEditorModel)
     {
         QueryEditorModel model = e.NewValue as QueryEditorModel;
         model.BuildStartCommand.CanExecuteTargets += () => true;
         model.BuildStartCommand.ExecuteTargets += (o) =>
         {
             // Source doesn't get updated for we need to move the
             // focus out for the bind to the source.
             TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
             UIElement element = Keyboard.FocusedElement as UIElement;
             if (element != null)
             {
                 element.MoveFocus(request);
                 element.Focus();
             }
         };
     }
 }
Ejemplo n.º 12
0
 private void Find_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         ComboBox comboBox = ((ComboBox)sender);
         if (comboBox.Text.Length > 0 && comboBox.Items != null && (comboBox.Items.Count == 0 || (string)comboBox.Items[0] != comboBox.Text))
         {
             comboBox.Items.Insert(0, comboBox.Text);
         }
         TraversalRequest tRequest = new TraversalRequest(FocusNavigationDirection.Next);
         UIElement keyboardFocus = Keyboard.FocusedElement as UIElement;
         if (keyboardFocus != null)
         {
             keyboardFocus.MoveFocus(tRequest);
         }
     }
     else
     {
         mainWindow.FindNextStringOnPage(FindText.Text, false, true, this.MatchCase.IsChecked ?? true, this.RegexFind.IsChecked ?? true);
     }
 }
Ejemplo n.º 13
0
 private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     TextBox textbox = (TextBox)sender;
     byte octet;
     if(!byte.TryParse(textbox.Text,out octet))
     {
         textbox.Text = "";
     }
     else
     {
         if (textbox.Text.Length == 3)
         {
             TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
             request.Wrapped = true;
             textbox.MoveFocus(request);
         }
     }
     if(firstOctet.Text!="" && secondOctet.Text!="" && thirdOctet.Text!="" && fourthOctet.Text != "")
     {
         calculate();
     }
     IPCalculation ipc = new IPCalculation(null, 1);
 }
Ejemplo n.º 14
0
        private void Weekdays_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {

            Action<FocusNavigationDirection> moveFocus = focusDirection =>
            {
                e.Handled = true;
                var request = new TraversalRequest(focusDirection);

                var focusedElement = Keyboard.FocusedElement as CheckBox;
                if (((string)focusedElement.Content == "SU" && request.FocusNavigationDirection == FocusNavigationDirection.Next))
                {
                    Monday.Focus();
                }
                else if (((string)focusedElement.Content == "MO" && request.FocusNavigationDirection == FocusNavigationDirection.Previous))
                {
                    Sunday.Focus();
                }
                else
                {
                    focusedElement.MoveFocus(request);
                }                
            };

            if (e.Key == Key.Down)
            {
                moveFocus(FocusNavigationDirection.Previous);
            }             
            else if (e.Key == Key.Up)
            {
                moveFocus(FocusNavigationDirection.Next);
            }           
            if (e.Key == Key.Tab)
            {
                Sunday.Focus();
            }              
        }
 bool IKeyboardInputSink.TabInto(TraversalRequest request)
 {
     return TabIntoCore(request);
 }
Ejemplo n.º 16
0
        /// <summary>
        ///     Helper method which handles the arrow key down
        /// </summary>
        /// <remarks>
        ///     ADO.Net has a bug (#524977) where if the row is in edit mode
        ///     and atleast one of the cells are edited and committed without
        ///     commiting the row itself, DataView.IndexOf for that row returns -1
        ///     and DataView.Contains returns false. The Workaround to this problem
        ///     is to try to use the previously computed row index if the operations
        ///     are in the same row scope.
        /// </remarks>
        private void OnArrowKeyDown(KeyEventArgs e)
        {
            DataGridCell currentCellContainer = CurrentCellContainer;
            if (currentCellContainer != null)
            {
                e.Handled = true;
                bool wasEditing = currentCellContainer.IsEditing;
                KeyboardNavigation keyboardNavigation = KeyboardNavigation.Current;

                UIElement startElement = Keyboard.FocusedElement as UIElement;
                ContentElement startContentElement = (startElement == null) ? Keyboard.FocusedElement as ContentElement : null;
                if ((startElement != null) || (startContentElement != null))
                {
                    bool navigateFromCellContainer = e.OriginalSource == currentCellContainer;
                    if (navigateFromCellContainer)
                    {
                        KeyboardNavigationMode keyboardNavigationMode = KeyboardNavigation.GetDirectionalNavigation(this);
                        if (keyboardNavigationMode == KeyboardNavigationMode.Once)
                        {
                            // KeyboardNavigation will move the focus out of the DataGrid
                            DependencyObject nextFocusTarget = this.PredictFocus(KeyToTraversalDirection(e.Key));
                            if (nextFocusTarget != null && !keyboardNavigation.IsAncestorOfEx(this, nextFocusTarget))
                            {
                                Keyboard.Focus(nextFocusTarget as IInputElement);
                            }

                            return;
                        }

                        int currentDisplayIndex = this.CurrentColumn.DisplayIndex;
                        ItemInfo currentInfo = CurrentInfo;
                        int currentRowIndex = currentInfo.Index;

                        int nextDisplayIndex = currentDisplayIndex;
                        int nextRowIndex = currentRowIndex;
                        bool controlModifier = ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) == ModifierKeys.Control);

                        // if we're at a boundary, try using default navigation - it can
                        // go to an element in a header/footer, rather than in another row.
                        if (!controlModifier && (e.Key == Key.Up || e.Key == Key.Down))
                        {
                            bool tryDefaultNavigation = false;

                            if (currentInfo.Item == CollectionView.NewItemPlaceholder)
                            {
                                tryDefaultNavigation = true;
                            }
                            else if (IsGrouping)
                            {
                                GroupItem currentGroupItem = DataGridHelper.FindVisualParent<GroupItem>(currentCellContainer);
                                if (currentGroupItem != null)
                                {
                                    CollectionViewGroupInternal cvg = ItemContainerGenerator.ItemFromContainer(currentGroupItem) as CollectionViewGroupInternal;
                                    if (cvg != null && cvg.Items.Count > 0)
                                    {
                                        // Try default navigation if current item is first or last item of a group.
                                        if ((e.Key == Key.Up && Object.Equals(cvg.Items[0], currentInfo.Item)) ||
                                            (e.Key == Key.Down && Object.Equals(cvg.Items[cvg.Items.Count - 1], currentInfo.Item)))
                                        {
                                            // there might be duplicate items, so double-check the index
                                            // (this is mildly expensive, which is why we put it off until necessary)
                                            int indexOfGroupBoundary = cvg.LeafIndexFromItem(null, 0);
                                            if (e.Key == Key.Down)
                                            {
                                                indexOfGroupBoundary += cvg.ItemCount - 1;
                                            }
                                            if (currentRowIndex == indexOfGroupBoundary)
                                            {
                                                tryDefaultNavigation = true;
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if ((e.Key == Key.Up && currentRowIndex == 0) ||
                                    (e.Key == Key.Down && currentRowIndex == Items.Count - 1))
                                {
                                    tryDefaultNavigation = true;
                                }
                            }

                            if (tryDefaultNavigation)
                            {
                                if (TryDefaultNavigation(e, currentInfo))
                                    return;
                            }
                        }

                        // Reverse the navigation in RTL flow direction
                        Key rtlKey = e.Key;
                        if (this.FlowDirection == FlowDirection.RightToLeft)
                        {
                            if (rtlKey == Key.Left)
                            {
                                rtlKey = Key.Right;
                            }
                            else if (rtlKey == Key.Right)
                            {
                                rtlKey = Key.Left;
                            }
                        }

                        switch (rtlKey)
                        {
                            case Key.Left:
                                if (controlModifier)
                                {
                                    nextDisplayIndex = InternalColumns.FirstVisibleDisplayIndex;
                                }
                                else
                                {
                                    nextDisplayIndex--;
                                    while (nextDisplayIndex >= 0)
                                    {
                                        DataGridColumn column = ColumnFromDisplayIndex(nextDisplayIndex);
                                        if (column.IsVisible)
                                        {
                                            break;
                                        }

                                        nextDisplayIndex--;
                                    }

                                    if (nextDisplayIndex < 0)
                                    {
                                        if (keyboardNavigationMode == KeyboardNavigationMode.Cycle)
                                        {
                                            nextDisplayIndex = InternalColumns.LastVisibleDisplayIndex;
                                        }
                                        else if (keyboardNavigationMode == KeyboardNavigationMode.Contained)
                                        {
                                            DependencyObject nextFocusTarget = keyboardNavigation.PredictFocusedElement(currentCellContainer, KeyToTraversalDirection(rtlKey),
                                                treeViewNavigation:false, considerDescendants:false);
                                            if (nextFocusTarget != null && keyboardNavigation.IsAncestorOfEx(this, nextFocusTarget))
                                            {
                                                Keyboard.Focus(nextFocusTarget as IInputElement);
                                            }
                                            return;
                                        }
                                        else // Continue, Local, None - move focus out of the datagrid
                                        {
                                            MoveFocus(new TraversalRequest(e.Key == Key.Left ? FocusNavigationDirection.Left : FocusNavigationDirection.Right));
                                            return;
                                        }
                                    }
                                }

                                break;

                            case Key.Right:
                                if (controlModifier)
                                {
                                    nextDisplayIndex = Math.Max(0, InternalColumns.LastVisibleDisplayIndex);
                                }
                                else
                                {
                                    nextDisplayIndex++;
                                    int columnCount = Columns.Count;
                                    while (nextDisplayIndex < columnCount)
                                    {
                                        DataGridColumn column = ColumnFromDisplayIndex(nextDisplayIndex);
                                        if (column.IsVisible)
                                        {
                                            break;
                                        }

                                        nextDisplayIndex++;
                                    }

                                    if (nextDisplayIndex >= Columns.Count)
                                    {
                                        if (keyboardNavigationMode == KeyboardNavigationMode.Cycle)
                                        {
                                            nextDisplayIndex = InternalColumns.FirstVisibleDisplayIndex;
                                        }
                                        else if (keyboardNavigationMode == KeyboardNavigationMode.Contained)
                                        {
                                            DependencyObject nextFocusTarget = keyboardNavigation.PredictFocusedElement(currentCellContainer, KeyToTraversalDirection(rtlKey),
                                                treeViewNavigation:false, considerDescendants:false);
                                            if (nextFocusTarget != null && keyboardNavigation.IsAncestorOfEx(this, nextFocusTarget))
                                            {
                                                Keyboard.Focus(nextFocusTarget as IInputElement);
                                            }
                                            return;
                                        }
                                        else // Continue, Local, None - move focus out of the datagrid
                                        {
                                            MoveFocus(new TraversalRequest(e.Key == Key.Left ? FocusNavigationDirection.Left : FocusNavigationDirection.Right));
                                            return;
                                        }
                                    }
                                }

                                break;

                            case Key.Up:
                                if (controlModifier)
                                {
                                    nextRowIndex = 0;
                                }
                                else
                                {
                                    nextRowIndex--;
                                    if (nextRowIndex < 0)
                                    {
                                        if (keyboardNavigationMode == KeyboardNavigationMode.Cycle)
                                        {
                                            nextRowIndex = Items.Count - 1;
                                        }
                                        else if (keyboardNavigationMode == KeyboardNavigationMode.Contained)
                                        {
                                            DependencyObject nextFocusTarget = keyboardNavigation.PredictFocusedElement(currentCellContainer, KeyToTraversalDirection(rtlKey),
                                                treeViewNavigation:false, considerDescendants:false);
                                            if (nextFocusTarget != null && keyboardNavigation.IsAncestorOfEx(this, nextFocusTarget))
                                            {
                                                Keyboard.Focus(nextFocusTarget as IInputElement);
                                            }
                                            return;
                                        }
                                        else // Continue, Local, None - move focus out of the datagrid
                                        {
                                            MoveFocus(new TraversalRequest(FocusNavigationDirection.Up));
                                            return;
                                        }
                                    }
                                }

                                break;

                            case Key.Down:
                            default:
                                if (controlModifier)
                                {
                                    nextRowIndex = Math.Max(0, Items.Count - 1);
                                }
                                else
                                {
                                    nextRowIndex++;
                                    if (nextRowIndex >= Items.Count)
                                    {
                                        if (keyboardNavigationMode == KeyboardNavigationMode.Cycle)
                                        {
                                            nextRowIndex = 0;
                                        }
                                        else if (keyboardNavigationMode == KeyboardNavigationMode.Contained)
                                        {
                                            DependencyObject nextFocusTarget = keyboardNavigation.PredictFocusedElement(currentCellContainer, KeyToTraversalDirection(rtlKey),
                                                treeViewNavigation:false, considerDescendants:false);
                                            if (nextFocusTarget != null && keyboardNavigation.IsAncestorOfEx(this, nextFocusTarget))
                                            {
                                                Keyboard.Focus(nextFocusTarget as IInputElement);
                                            }
                                            return;
                                        }
                                        else // Continue, Local, None - move focus out of the datagrid
                                        {
                                            MoveFocus(new TraversalRequest(FocusNavigationDirection.Down));
                                            return;
                                        }
                                    }
                                }

                                break;
                        }

                        DataGridColumn nextColumn = ColumnFromDisplayIndex(nextDisplayIndex);
                        ItemInfo nextInfo = ItemInfoFromIndex(nextRowIndex);
                        ScrollCellIntoView(nextInfo, nextColumn);
                        DataGridCell nextCellContainer = TryFindCell(nextInfo, nextColumn);

                        if (nextCellContainer == null || nextCellContainer == currentCellContainer || !nextCellContainer.Focus())
                        {
                            return;
                        }
                    }

                    else
                    {
                        if (TryDefaultNavigation(e, null))
                            return;
                    }

                    // Attempt to move focus
                    TraversalRequest request = new TraversalRequest(KeyToTraversalDirection(e.Key));
                    if (navigateFromCellContainer ||
                        ((startElement != null) && startElement.MoveFocus(request)) ||
                        ((startContentElement != null) && startContentElement.MoveFocus(request)))
                    {
                        SelectAndEditOnFocusMove(e, currentCellContainer, wasEditing, /* allowsExtendSelect = */ true, /* ignoreControlKey = */ true);
                    }
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        ///     Called when the tab key is pressed to perform focus navigation.
        /// </summary>
        private void OnTabKeyDown(KeyEventArgs e)
        {
            // When the end-user uses the keyboard to tab to another cell while the current cell
            // is in edit-mode, then the next cell should enter edit mode in addition to gaining
            // focus. There is no way to detect this from the focus change events, so the cell
            // is going to handle the complete operation manually.
            // The standard focus change method is being called here, so even if focus moves
            // to something other than a cell, focus should land on the element that it would
            // have landed on anyway.
            DataGridCell currentCellContainer = CurrentCellContainer;
            if (currentCellContainer != null)
            {
                bool wasEditing = currentCellContainer.IsEditing;
                bool previous = ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift);

                // Start navigation from the current focus to allow moveing focus on other focusable elements inside the cell
                UIElement startElement = Keyboard.FocusedElement as UIElement;
                ContentElement startContentElement = (startElement == null) ? Keyboard.FocusedElement as ContentElement : null;
                if ((startElement != null) || (startContentElement != null))
                {
                    e.Handled = true;

                    FocusNavigationDirection direction = previous ? FocusNavigationDirection.Previous : FocusNavigationDirection.Next;
                    TraversalRequest request = new TraversalRequest(direction);

                    // Move focus to the the next or previous tab stop.
                    if (((startElement != null) && startElement.MoveFocus(request)) ||
                        ((startContentElement != null) && startContentElement.MoveFocus(request)))
                    {
                        // If focus moved to the cell while in edit mode - keep navigating to the previous cell
                        if (wasEditing && previous && Keyboard.FocusedElement == currentCellContainer)
                        {
                            currentCellContainer.MoveFocus(request);
                        }

                        // In case of grouping if a row level commit happened due to
                        // the previous focus change, the container of the row gets
                        // removed from the visual tree by the CollectionView,
                        // but we still hang on to a cell of that row, which will be used
                        // by the call to SelectAndEditOnFocusMove. Hence re-establishing the
                        // focus appropriately in such cases.
                        if (IsGrouping && wasEditing)
                        {
                            DataGridCell newCell = GetCellForSelectAndEditOnFocusMove();

                            if (newCell != null &&
                                newCell.RowDataItem == currentCellContainer.RowDataItem)
                            {
                                DataGridCell realNewCell = TryFindCell(ItemInfoFromContainer(newCell.RowOwner), newCell.Column);

                                // Forcing an UpdateLayout since the generation of the new row
                                // container which was removed earlier is done in measure.
                                if (realNewCell == null)
                                {
                                    UpdateLayout();
                                    realNewCell = TryFindCell(ItemInfoFromContainer(newCell.RowOwner), newCell.Column);
                                }
                                if (realNewCell != null && realNewCell != newCell)
                                {
                                    realNewCell.Focus();
                                }
                            }
                        }

                        // When doing TAB and SHIFT+TAB focus movement, don't confuse the selection
                        // code, which also relies on SHIFT to know whether to extend selection or not.
                        SelectAndEditOnFocusMove(e, currentCellContainer, wasEditing, /* allowsExtendSelect = */ false, /* ignoreControlKey = */ true);
                    }
                }
            }
        }
Ejemplo n.º 18
0
        private void TextBox_OnKeyDown(object sender, KeyEventArgs e)
        {
            bool move = e.Key == Key.Enter | e.Key == Key.Up | e.Key == Key.Down;
            bool up = e.Key == Key.Enter ? ( ( Keyboard.IsKeyDown( Key.LeftShift ) | Keyboard.IsKeyDown( Key.RightShift ) ) )
                : e.Key == Key.Up;
            if ( move )
            {
                // we need to delay this until after the text is changed
                var box = sender as TextBox;
                BindingExpression be = box.GetBindingExpression( TextBox.TextProperty );
                be.UpdateSource();
                // MoveFocus takes a TraversalRequest as its argument.
                TraversalRequest request = new TraversalRequest(
                   up ? FocusNavigationDirection.Previous : FocusNavigationDirection.Next );

                // Gets the element with keyboard focus.
                UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;

                // Change keyboard focus.
                if ( elementWithFocus != null )
                {
                    elementWithFocus.MoveFocus( request );
                }
            }
        }
Ejemplo n.º 19
0
 private void Window_PreviewMouseDown(object sender, MouseButtonEventArgs e)
 {
     FocusNavigationDirection focusDirection = FocusNavigationDirection.Up;   //可以是其他方向键.它是一个枚举值.
     TraversalRequest request = new TraversalRequest(focusDirection);
     txtSearch.MoveFocus(request);
 }
Ejemplo n.º 20
0
 bool IKeyboardInputSite.OnNoMoreTabStops(TraversalRequest request)
 { 
     return Browser.TabOut(request.FocusNavigationDirection == FocusNavigationDirection.Next); 
     // i. Tabbing-in is handled by ApplicationProxyInternal.
 } 
Ejemplo n.º 21
0
 internal void TabInto(bool forward) 
 {
     TraversalRequest tr = new TraversalRequest(
         forward ? FocusNavigationDirection.First : FocusNavigationDirection.Last);
     MoveFocus(tr); 
 }
 protected virtual bool TabIntoCore(TraversalRequest request)
 {
     return false;
 }
Ejemplo n.º 23
0
 bool IAvalonAdapter.OnNoMoreTabStops(TraversalRequest request, ref bool ShouldCycle)
 {
     return(false);
 }
Ejemplo n.º 24
0
        // Keyboard
        /// <summary> 
        ///     Request to move the focus from this element to another element
        /// </summary>
        /// <param name="request">
        ///     The direction that focus is to move. 
        /// </param>
        /// <returns> Returns true if focus is moved successfully. Returns false if there is no next element</returns> 
        public sealed override bool MoveFocus(TraversalRequest request) 
        {
            if (request == null) 
            {
                throw new ArgumentNullException("request");
            }
 
            return KeyboardNavigation.Current.Navigate(this, request);
        } 
Ejemplo n.º 25
0
 /// <internalonly>
 ///     Forwards focus from Windows Presentation Foundation to the hosted Windows Forms control.
 /// </internalonly>
 public virtual bool TabInto(SWI.TraversalRequest request)
 {
     return(HostContainerInternal.FocusNext(request));
 }
        private void ListView_StatusChanged(ListView listView, EventArgs e)
        {
            DebugHelper.AssertUIThread();

            if ((listView != null) && (e != null))
            {
                if (listView.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
                {
                    if (this.setNextMetadatFocus == listView)
                    {
                        int newIndex = listView.SelectedIndex;
                        this.setNextMetadatFocus = null;

                        if (newIndex >= 0)
                        {
                            Dispatcher.BeginInvoke(new Action(() =>
                                {
                                    FrameworkElement itemContainer = listView.ItemContainerGenerator.ContainerFromIndex(newIndex) as FrameworkElement;
                                    if (itemContainer != null)
                                    {
                                        TraversalRequest traversalRequest = new TraversalRequest(FocusNavigationDirection.Last);
                                        itemContainer.MoveFocus(traversalRequest);
                                    }
                                }));
                        }
                    }

                    if (!this.dragging)
                    {
                        if (listView == this.PublicMetadataItemsControl)
                        {
                            this.PublicKeyWidth = (double)this.GetValue(MetadataViewContent.PublicKeyWidthProperty);
                            this.PublicValueWidth = (double)this.GetValue(MetadataViewContent.PublicValueWidthProperty);
                        }
                        else if (listView == this.PersonalMetadataItemsControl)
                        {
                            this.PersonalKeyWidth = (double)this.GetValue(MetadataViewContent.PersonalKeyWidthProperty);
                            this.PersonalValueWidth = (double)this.GetValue(MetadataViewContent.PersonalValueWidthProperty);
                        }
                    }
                }
            };
        }
Ejemplo n.º 27
0
            public bool OnNoMoreTabStops(TraversalRequest request)
            {
                // First, determine if we are tabbing forward or backwards
                // outside of our content.
                bool forward = true;
                if (request != null)
                {
                    switch (request.FocusNavigationDirection)
                    {
                        case FocusNavigationDirection.Next:
                        case FocusNavigationDirection.Right:
                        case FocusNavigationDirection.Down:
                            forward = true;
                            break;

                        case FocusNavigationDirection.Previous:
                        case FocusNavigationDirection.Left:
                        case FocusNavigationDirection.Up:
                            forward = false;
                            break;
                    }
                }

                // Based on the direction, tab forward or backwards in our parent dialog.
                IntPtr nextHandle = DialogPageElementHost.GetNextFocusElement(_source.Handle, forward);
                if (nextHandle != IntPtr.Zero)
                {
                    // If we were able to find another control, send focus to it and inform
                    // WPF that we moved focus outside the HwndSource.
                    NativeMethods.SetFocus(nextHandle);
                    return true;
                }

                // If we couldn't find a dialog item to focus, inform WPF that it should
                // continue cycling inside its own tab order.
                return false;
            }
Ejemplo n.º 28
0
        private void GridPathologist_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.F7)
            {
                TraversalRequest traversalRequestNext = new TraversalRequest(FocusNavigationDirection.Next);
                UIElement keyboardFocus = Keyboard.FocusedElement as UIElement;

                if(keyboardFocus != null)
                {
                    keyboardFocus.MoveFocus(traversalRequestNext);
                }

                this.m_PathologistUI.SpellCheckCurrentItem();
                e.Handled = true;
            }
        }
				public bool OnNoMoreTabStops(TraversalRequest request)
				{
					var flag = true;
					if (request != null)
					{
						switch (request.FocusNavigationDirection)
						{
							case FocusNavigationDirection.Next:
							case FocusNavigationDirection.Right:
							case FocusNavigationDirection.Down:
								flag = true;
								break;
							case FocusNavigationDirection.Previous:
							case FocusNavigationDirection.Left:
							case FocusNavigationDirection.Up:
								flag = false;
								break;
						}
					}

					var ancestor = NativeMethods.GetAncestor(this.source.Handle, 2);
					if (ancestor != IntPtr.Zero)
					{
						var hWnd = NativeMethods.GetNextDlgTabItem(ancestor, this.source.Handle, !flag);
						if (hWnd != IntPtr.Zero)
						{
							NativeMethods.SetFocus(hWnd);
							return true;
						}
					}

					return false;
				}
Ejemplo n.º 30
0
        /// <summary>
        ///     Helper method which handles the arrow key down
        /// </summary>
        /// <remarks>
        ///     ADO.Net has a bug (#524977) where if the row is in edit mode
        ///     and atleast one of the cells are edited and committed without
        ///     commiting the row itself, DataView.IndexOf for that row returns -1
        ///     and DataView.Contains returns false. The Workaround to this problem 
        ///     is to try to use the previously computed row index if the operations 
        ///     are in the same row scope.
        /// </remarks>
        private void OnArrowKeyDown(KeyEventArgs e)
        {
            DataGridCell currentCellContainer = CurrentCellContainer;
            if (currentCellContainer != null)
            {
                e.Handled = true;
                bool wasEditing = currentCellContainer.IsEditing;

                UIElement startElement = Keyboard.FocusedElement as UIElement;
                ContentElement startContentElement = (startElement == null) ? Keyboard.FocusedElement as ContentElement : null;
                if ((startElement != null) || (startContentElement != null))
                {
                    bool navigateFromCellContainer = e.OriginalSource == currentCellContainer;
                    if (navigateFromCellContainer)
                    {
                        KeyboardNavigationMode keyboardNavigationMode = KeyboardNavigation.GetDirectionalNavigation(this);
                        if (keyboardNavigationMode == KeyboardNavigationMode.Once)
                        {
                            // KeyboardNavigation will move the focus out of the DataGrid
                            DependencyObject nextFocusTarget = this.PredictFocus(KeyToTraversalDirection(e.Key));
                            if (nextFocusTarget != null && !this.IsAncestorOf(nextFocusTarget))
                            {
                                Keyboard.Focus(nextFocusTarget as IInputElement);
                            }

                            return;
                        }

                        int currentDisplayIndex = this.CurrentColumn.DisplayIndex;
                        object currentItem = CurrentItem;
                        int currentRowIndex = Items.IndexOf(currentItem);

                        // ADO.Net bug HACK, see remarks.
                        if (_editingRowIndex >= 0 && currentItem == _editingRowItem)
                        {
                            currentRowIndex = _editingRowIndex;
                        }

                        int nextDisplayIndex = currentDisplayIndex;
                        int nextRowIndex = currentRowIndex;
                        bool controlModifier = ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) == ModifierKeys.Control);

                        // Reverse the navigation in RTL flow direction
                        Key rtlKey = e.Key;
                        if (this.FlowDirection == FlowDirection.RightToLeft)
                        {
                            if (rtlKey == Key.Left)
                            {
                                rtlKey = Key.Right;
                            }
                            else if (rtlKey == Key.Right)
                            {
                                rtlKey = Key.Left;
                            }
                        }

                        switch (rtlKey)
                        {
                            case Key.Left:
                                if (controlModifier)
                                {
                                    nextDisplayIndex = InternalColumns.FirstVisibleDisplayIndex;
                                }
                                else
                                {
                                    nextDisplayIndex--;
                                    while (nextDisplayIndex >= 0)
                                    {
                                        DataGridColumn column = ColumnFromDisplayIndex(nextDisplayIndex);
                                        if (column.IsVisible)
                                        {
                                            break;
                                        }
                             
                                        nextDisplayIndex--;
                                    }
                             
                                    if (nextDisplayIndex < 0)
                                    {
                                        if (keyboardNavigationMode == KeyboardNavigationMode.Cycle)
                                        {
                                            nextDisplayIndex = InternalColumns.LastVisibleDisplayIndex;
                                        }
                                        else if (keyboardNavigationMode == KeyboardNavigationMode.Contained)
                                        {
                                            return;
                                        }
                                        else // Continue, Local, None - move focus out of the datagrid
                                        {
                                            MoveFocus(new TraversalRequest(e.Key == Key.Left ? FocusNavigationDirection.Left : FocusNavigationDirection.Right));
                                            return;
                                        }
                                    }
                                }

                                break;

                            case Key.Right:
                                if (controlModifier)
                                {
                                    nextDisplayIndex = Math.Max(0, InternalColumns.LastVisibleDisplayIndex);
                                }
                                else
                                {
                                    nextDisplayIndex++;
                                    int columnCount = Columns.Count;
                                    while (nextDisplayIndex < columnCount)
                                    {
                                        DataGridColumn column = ColumnFromDisplayIndex(nextDisplayIndex);
                                        if (column.IsVisible)
                                        {
                                            break;
                                        }

                                        nextDisplayIndex++;
                                    }

                                    if (nextDisplayIndex >= Columns.Count)
                                    {
                                        if (keyboardNavigationMode == KeyboardNavigationMode.Cycle)
                                        {
                                            nextDisplayIndex = InternalColumns.FirstVisibleDisplayIndex;
                                        }
                                        else if (keyboardNavigationMode == KeyboardNavigationMode.Contained)
                                        {
                                            return;
                                        }
                                        else // Continue, Local, None - move focus out of the datagrid
                                        {
                                            MoveFocus(new TraversalRequest(e.Key == Key.Left ? FocusNavigationDirection.Left : FocusNavigationDirection.Right));
                                            return;
                                        }
                                    }
                                }

                                break;

                            case Key.Up:
                                if (controlModifier)
                                {
                                    nextRowIndex = 0;
                                }
                                else
                                {
                                    nextRowIndex--;
                                    if (nextRowIndex < 0)
                                    {
                                        if (keyboardNavigationMode == KeyboardNavigationMode.Cycle)
                                        {
                                            nextRowIndex = Items.Count - 1;
                                        }
                                        else if (keyboardNavigationMode == KeyboardNavigationMode.Contained)
                                        {
                                            return;
                                        }
                                        else // Continue, Local, None - move focus out of the datagrid
                                        {
                                            MoveFocus(new TraversalRequest(FocusNavigationDirection.Up));
                                            return;
                                        }
                                    }
                                }

                                break;

                            case Key.Down:
                            default:
                                if (controlModifier)
                                {
                                    nextRowIndex = Math.Max(0, Items.Count - 1);
                                }
                                else
                                {
                                    nextRowIndex++;
                                    if (nextRowIndex >= Items.Count)
                                    {
                                        if (keyboardNavigationMode == KeyboardNavigationMode.Cycle)
                                        {
                                            nextRowIndex = 0;
                                        }
                                        else if (keyboardNavigationMode == KeyboardNavigationMode.Contained)
                                        {
                                            return;
                                        }
                                        else // Continue, Local, None - move focus out of the datagrid
                                        {
                                            MoveFocus(new TraversalRequest(FocusNavigationDirection.Down));
                                            return;
                                        }
                                    }
                                }

                                break;
                        }

                        DataGridColumn nextColumn = ColumnFromDisplayIndex(nextDisplayIndex);
                        object nextItem = Items[nextRowIndex];
                        ScrollCellIntoView(nextItem, nextColumn);
                        DataGridCell nextCellContainer = TryFindCell(nextItem, nextColumn);

                        if (nextCellContainer == null || nextCellContainer == currentCellContainer || !nextCellContainer.Focus())
                        {
                            return;
                        }
                    }
 
                    // Attempt to move focus
                    TraversalRequest request = new TraversalRequest(KeyToTraversalDirection(e.Key));
                    if (navigateFromCellContainer ||
                        ((startElement != null) && startElement.MoveFocus(request)) ||
                        ((startContentElement != null) && startContentElement.MoveFocus(request)))
                    {
                        SelectAndEditOnFocusMove(e, currentCellContainer, wasEditing, /* allowsExtendSelect = */ true, /* ignoreControlKey = */ true);
                    }
                }
            }
        }
Ejemplo n.º 31
0
 static ModalContentPresenter()
 {
     traversalDirection =
         new TraversalRequest(FocusNavigationDirection.First);
 }
        private static bool MoveFocus(object source, TraversalRequest request)
        {
            var uiElement = source as UIElement;
            if (uiElement != null)
                return uiElement.MoveFocus(request);

            var contentElement = source as ContentElement;
            if (contentElement != null)
                return contentElement.MoveFocus(request);

            var uiElement3D = source as UIElement3D;
            if (uiElement3D != null)
                return uiElement3D.MoveFocus(request);

            return false;
        }
 // Delegate IKeyboardInputSink calls to the hosted HwndSource.
 protected override sealed bool TabIntoCore(TraversalRequest request)
 {
     if (_hwndSource != null) {
         return ((IKeyboardInputSink)_hwndSource).TabInto(request);
     } else {
         return base.TabIntoCore(request);
     }
 }
Ejemplo n.º 34
0
        /// <summary>
        ///     Components call this when they want to move focus ("tab") but
        ///     have nowhere further to tab within their own component.  Return
        ///     value is true if the site moved focus, false if the calling
        ///     component still has focus and should wrap around.
        /// </summary> 
        bool IKeyboardInputSite.OnNoMoreTabStops(TraversalRequest request)
        {
            bool traversed = false;

            if(_sinkElement != null)
            {
                traversed = _sinkElement.MoveFocus(request);
            }

            return traversed;
        }