コード例 #1
0
        protected override IList <FrameworkElement> GetCells()
        {
            var vte   = VisualTreeHelpers.GetVisualTreeEnumerator(Row, (v) => { return(v is VirtualTableCell); }, System.Windows.Input.FocusNavigationDirection.Next);
            var cells = new List <FrameworkElement>();

            while (vte.MoveNext())
            {
                cells.Add(vte.Current as VirtualTableCell);
            }
            return(cells);
        }
コード例 #2
0
        public void UpdateFocus()
        {
            if (focusDeferCount > 0)
            {
                hasPendingFocus = true;
                return;
            }

            hasPendingFocus = false;

            if (!TargetElement.IsKeyboardFocusWithin)
            {
                log.DebugFormat("Ignoring UpdateFocus() request on {0}, because it does not have keyboard focus.", TargetElement);
                return;
            }

            log.DebugFormat("Begin updating focus on {0}", TargetElement);

            if (nextFocusUpdateOperation != null)
            {
                nextFocusUpdateOperation.Abort();
            }

            IsRestoringFocusOnElement = isRestoringState.IsSet;

            nextFocusUpdateOperation = TargetElement.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
            {
                using (new DisposalActionCaller(() => IsRestoringFocusOnElement = false))
                {
                    log.DebugFormat("Updating focus on {0}", TargetElement);
                    using (LoggingExtensions.Indent())
                    {
                        //IElementEditStateService editStateService = null;
                        //if (currentCellService.CurrentItemContainer != null)
                        //   editStateService = UIServiceProvider.GetService<IElementEditStateService>(currentCellService.CurrentItemContainer, false);

                        //if (editStateService == null)
                        //   editStateService = UIServiceProvider.GetService<IElementEditStateService>(TargetElement);

                        var elementToFocus = currentCellService.CurrentCellContainer;
                        if (elementToFocus == null)
                        {
                            return;
                        }

                        if (elementToFocus.IsFocused)
                        {
                            log.DebugFormat("The cell {0} is already in focus.", elementToFocus);
                            return;
                        }

                        var vte = VisualTreeHelpers.GetVisualTreeEnumerator(elementToFocus,
                                                                            (v) => { return((v is UIElement) && ((UIElement)v).Focusable); }, FocusNavigationDirection.Next);
                        while (vte.MoveNext())
                        {
                            elementToFocus = vte.Current as FrameworkElement;
                        }
                        log.DebugFormat("Trying to set focus on element {0}", elementToFocus);
                        using (isUpdatingFocus.Set())
                        {
                            bool isFocused = elementToFocus.Focus();
                            log.DebugFormat("Focus result: {0}, Focused element is {1}", isFocused, Keyboard.FocusedElement);
                        }
                        isFirstFocus             = false;
                        nextFocusUpdateOperation = null;
                    }
                }
            }));
        }