public bool MoveTo(UniversalCellInfo targetCell)
        {
            if (inMoveTo.IsSet)
            {
                return(true);
            }

            return((bool)dataGrid.Dispatcher.Invoke(DispatcherPriority.Loaded, new Func <bool>(() =>
            {
                bool canceled;

                log.DebugFormat("Moving to cell {0}", targetCell);

                UpdateCurrentCell();

                if (!CanMoveTo(targetCell))
                {
                    return CannotMoveToCell(targetCell);
                }

                if (!suppressChangeNotifications.IsSet)
                {
                    RaisePreviewCurrentCellChangingEvent(targetCell, out canceled);
                    if (canceled)
                    {
                        return OperationCanceled();
                    }
                }

                using (isSelfInducedCellChange.Set())
                {
                    if (targetCell.CellIndex >= dataGrid.Columns.Count)
                    {
                        return false;
                    }

                    var rowEnumSvc = GetRowEnumerationServiceForItem(targetCell.Item);
                    // If changing the row type (according to the row service), we should retake the cell index.
                    if (CurrentRowCellEnumerationService == null ||
                        rowEnumSvc.ServiceGroupIdentifier.Equals(CurrentRowCellEnumerationService.ServiceGroupIdentifier))
                    {
                        currentCellPosition.SetCurrentCellIndex(rowEnumSvc, targetCell.CellIndex);
                    }

                    var newCell = rowEnumSvc.GetCellInfo(currentCellPosition.GetCurrentCellIndex(rowEnumSvc));
                    var fm = UIServiceProvider.GetService <IFocusManagementService>(dataGrid);
                    elementTraits.SetCurrentCell(this.dataGrid, newCell);
                    UpdateCurrentCell();
                    fm.SetFocusOnTargetElement();

                    if (!suppressChangeNotifications.IsSet)
                    {
                        RaiseCurrentCellChangedEvent();
                    }
                }
                return CurrentCell.Equals(targetCell);
            })));
        }
Ejemplo n.º 2
0
        public override bool Equals(object obj)
        {
            if (!(obj is UniversalCellInfo))
            {
                return(false);
            }

            UniversalCellInfo other = (UniversalCellInfo)obj;

            return(object.ReferenceEquals(this.Item, other.Item) && (this.CellIndex == other.CellIndex));
        }
        /// <summary>
        /// Retrieves the actual cell that the data grid holds as 'current'.
        /// </summary>
        /// <returns></returns>
        private UniversalCellInfo GetCurrentCell()
        {
            UniversalCellInfo cell = UniversalCellInfo.Undefined;

            CurrentRowCellEnumerationService = GetRowEnumerationServiceForItem(dataGrid.CurrentItem);
            if (CurrentRowCellEnumerationService != null)
            {
                cell = CurrentRowCellEnumerationService.GetCellInfo(currentCellPosition.GetCurrentCellIndex(CurrentRowCellEnumerationService));
            }

            return(cell);
        }
 /// <summary>
 /// Raises the PreviewCurrentCellChangingEvent without allowing canceling of the event.
 /// </summary>
 public void RaiseNonCancelablePreviewCurrentCellChangingEvent(UniversalCellInfo newValue)
 {
     if (PreviewCurrentCellChanging != null)
     {
         var eventArgs = new PreviewChangeEventArgs(CurrentCell, newValue, false);
         PreviewCurrentCellChanging(this, eventArgs);
     }
     if (PreviewCurrentChanging != null && CurrentCell.Item != newValue.Item)
     {
         isCurrentItemChanged = true;
         var eventArgs = new PreviewChangeEventArgs(CurrentCell.Item, newValue.Item, false);
         PreviewCurrentChanging(this, eventArgs);
     }
 }
 /// <summary>
 /// Raises the PreviewCurrentCellChangingEvent, allowing the handlers to cancel it,
 /// returning the result in 'canceled'
 /// </summary>
 ///
 /// <param name="canceled">Returns whether any of the event handlers canceled the event.</param>
 public void RaisePreviewCurrentCellChangingEvent(UniversalCellInfo newValue, out bool canceled)
 {
     canceled = false;
     if (PreviewCurrentCellChanging != null)
     {
         var eventArgs = new PreviewChangeEventArgs(CurrentCell, newValue, true);
         PreviewCurrentCellChanging(this, eventArgs);
         canceled = eventArgs.Canceled;
     }
     if (!canceled)
     {
         if (PreviewCurrentChanging != null && CurrentCell.Item != newValue.Item)
         {
             var eventArgs = new PreviewChangeEventArgs(CurrentCell.Item, newValue.Item, false);
             PreviewCurrentChanging(this, eventArgs);
             canceled             = eventArgs.Canceled;
             isCurrentItemChanged = !canceled;
         }
     }
 }
        private bool CanMoveTo(UniversalCellInfo targetCell)
        {
            if (IndexOf(targetCell.Item) < 0)
            {
                return(false);
            }

            var targetRowCellEnumerationService = GetRowEnumerationServiceForItem(targetCell.Item);

            if (targetRowCellEnumerationService == null)
            {
                return(false);
            }

            if (targetCell.CellIndex < 0 || targetCell.CellIndex >= targetRowCellEnumerationService.CellCount)
            {
                return(false);
            }

            return(true);
        }
        private void MouseClicked(MouseEventArgs eventArgs)
        {
            log.Debug("Mouse was clicked on " + eventArgs.OriginalSource);

            var focusManager = UIServiceProvider.GetService <IFocusManagementService>(TargetElement);

            focusManager.SetFocusOnTargetElement();

            HitTestResult hitTestResult = VisualTreeHelper.HitTest(TargetElement, Mouse.GetPosition(TargetElement));
            var           row           = UIUtils.GetAncestor <DataGridRow>((Visual)hitTestResult.VisualHit);

            if (row != null)
            {
                var rowEnumSvc             = UIServiceProvider.GetService <ICellEnumerationService>(row);
                UniversalCellInfo cellInfo = rowEnumSvc.GetCellContaining(hitTestResult.VisualHit);
                if (!currentCellService.CurrentCell.Equals(cellInfo))
                {
                    currentCellService.MoveTo(cellInfo);
                    eventArgs.Handled = true;
                }
            }
        }
Ejemplo n.º 8
0
        public void SetCurrentCell(ItemsControl control, UniversalCellInfo cellInfo)
        {
            var dg = (DataGrid)control;

            dg.CurrentCell = new DataGridCellInfo(cellInfo.Item, dg.ColumnFromDisplayIndex(cellInfo.CellIndex));
        }
 private bool CannotMoveToCell(UniversalCellInfo targetCell)
 {
     log.DebugFormat("Cannot move to cell {0}", targetCell);
     return(false);
 }