Exemplo n.º 1
0
        public void AttachToElement(FrameworkElement element)
        {
            //if (TargetElement != null)
            //{
            //   if (ReferenceEquals(TargetElement.ElementSelectionService, element))
            //   {
            //      log.DebugFormat("Extender {0} is already attached to element {1}", this, element);
            //      return;
            //   }
            //   throw new InvalidOperationException("Cannot re-attach an attached extender");
            //}

            TargetElementProxy = UIServiceProvider.GetService <IMultiSelectionService>(element);
            SetSelectionExtender(element, this);
            var selectionView = GetSelectionView(element);

            this.AttachSelectionModel(null, selectionView);
            TargetElementProxy.SelectionChanged += TargetElement_SelectionChanged;

            currentItemTracker = UIServiceProvider.GetService <ICurrentItemService>(element, false);
            currentItemTracker.CurrentChanged         += new EventHandler(currentItemTracker_CurrentChanged);
            currentItemTracker.PreviewCurrentChanging += CurrentItemTracker_PreviewCurrentChanging;
            //if (currentItemTracker != null)
            //{
            //   selectionModeManager = new SelectionModeManager(TargetElement);
            //}

            var inputService = UIServiceProvider.GetService <InputService>(TargetElement);

            inputService.RegisterMouseActionGestures(ToggleSelection, new MouseGesturesFactory(MouseAction.LeftClick, ModifierKeys.Control));
            inputService.RegisterKeyActionGestures(ToggleSelection, new KeyGesturesFactory(Key.Space, ModifierKeys.Control));
            //inputService.RegisterMouseActionGestures(SelectRange, new MouseGesturesFactory(MouseAction.LeftClick, ModifierKeys.Shift));
        }
        private void DataGrid_CurrentCellChanged(object sender, EventArgs e)
        {
            var fm = UIServiceProvider.GetService <IFocusManagementService>(dataGrid);

            if (fm.IsRestoringFocusOnElement)
            {
                // The data grid is loosing focus, in which case it automatically sets 'CurrentCell' to be 'null'.
                // We need to ignore this case so nothing will be changed on screen.
                return;
            }

            if (!isSelfInducedCellChange.IsSet)
            {
                RaiseNonCancelablePreviewCurrentCellChangingEvent(CurrentCell);
                var newRowService = GetRowEnumerationServiceForItem(dataGrid.CurrentCell.Item);
                if (newRowService != null)
                {
                    var columnIndex = 0;
                    if (dataGrid.CurrentCell.Column != null)
                    {
                        columnIndex = dataGrid.CurrentCell.Column.DisplayIndex;
                    }

                    currentCellPosition.SetCurrentCellIndex(newRowService, columnIndex);
                }
            }
            UpdateCurrentCell();
            if (!isSelfInducedCellChange.IsSet)
            {
                RaiseCurrentCellChangedEvent();
            }
        }
        protected override void Setup()
        {
            currentCellService = UIServiceProvider.GetService <ICurrentCellService>(TargetElement);
            Debug.Assert(currentCellService != null);

            inputService = UIServiceProvider.GetService <InputService>(TargetElement);
            Debug.Assert(inputService != null);

            scrollService = UIServiceProvider.GetService <IVerticalScrollService>(TargetElement);
            Debug.Assert(scrollService != null);

            inputService.RegisterKeyActionGestures(AsLineKeyAction(MoveLineDown), new KeyGesturesFactory(Key.Down, InputGesturesFactory.AllCombinationsOf(ModifierKeys.Control, ModifierKeys.Shift)));
            inputService.RegisterKeyActionGestures(AsLineKeyAction(MoveLineUp), new KeyGesturesFactory(Key.Up, InputGesturesFactory.AllCombinationsOf(ModifierKeys.Control, ModifierKeys.Shift)));
            inputService.RegisterKeyActionGestures(AsLineKeyAction(MovePageDown), new KeyGesturesFactory(Key.PageDown, InputGesturesFactory.AllCombinationsOf(ModifierKeys.Control, ModifierKeys.Shift)));
            inputService.RegisterKeyActionGestures(AsLineKeyAction(MovePageUp), new KeyGesturesFactory(Key.PageUp, InputGesturesFactory.AllCombinationsOf(ModifierKeys.Control, ModifierKeys.Shift)));
            inputService.RegisterKeyActionGestures(AsLineKeyAction(MoveToTop), new KeyGesturesFactory(Key.Home, ModifierKeys.Control));
            inputService.RegisterKeyActionGestures(AsLineKeyAction(MoveToBottom), new KeyGesturesFactory(Key.End, ModifierKeys.Control));

            inputService.RegisterKeyActionGestures(AsFieldKeyAction(MoveRight), new KeyGesturesFactory(Key.Tab));
            inputService.RegisterKeyActionGestures(AsFieldKeyAction(MoveRight), new KeyGesturesFactory(Key.Right, InputGesturesFactory.AllCombinationsOf(ModifierKeys.Control, ModifierKeys.Shift)));

            inputService.RegisterKeyActionGestures(AsFieldKeyAction(MoveLeft), new KeyGesturesFactory(Key.Tab, ModifierKeys.Shift));
            inputService.RegisterKeyActionGestures(AsFieldKeyAction(MoveLeft), new KeyGesturesFactory(Key.Left, InputGesturesFactory.AllCombinationsOf(ModifierKeys.Control, ModifierKeys.Shift)));

            inputService.RegisterKeyActionGestures(AsFieldKeyAction(MoveToLeftMost), new KeyGesturesFactory(Key.Home));
            inputService.RegisterKeyActionGestures(AsFieldKeyAction(MoveToRightMost), new KeyGesturesFactory(Key.End));

            inputService.RegisterMouseActionGestures(MouseClicked, new MouseGesturesFactory(MouseAction.LeftClick, InputGesturesFactory.AllCombinationsOf(ModifierKeys.Shift, ModifierKeys.Control)));
        }
        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);
            })));
        }
Exemplo n.º 5
0
        private void EnableEditing()
        {
            var editSvc = UIServiceProvider.GetService <IElementEditStateService>(TargetElement, false);

            if (editSvc != null)
            {
                editSvc.EnableEditing();
            }
        }
        public void AttachToElement(FrameworkElement element)
        {
            TargetElement      = element;
            currentCellService = UIServiceProvider.GetService <ICurrentCellService>(TargetElement);
            currentCellService.CurrentCellChanged += new EventHandler(currentCellService_CurrentCellChanged);

            TargetElement.PreviewGotKeyboardFocus  += TargetElement_PreviewGotKeyboardFocus;
            TargetElement.PreviewLostKeyboardFocus += TargetElement_PreviewLostKeyboardFocus;
        }
Exemplo n.º 7
0
        private bool DisableEditing()
        {
            var editSvc = UIServiceProvider.GetService <IElementEditStateService>(TargetElement, false);

            if (editSvc != null)
            {
                return(editSvc.DisableEditing());
            }
            return(true);
        }
        private ICellEnumerationService GetRowEnumerationServiceForItem(object item)
        {
            log.DebugFormat(FrameworkElementFormatter.GetInstance(), "Trying to get row enumeration service for {0}", item);

            var currentRow = GetItemContainer(item) as DataGridRow;

            if (currentRow == null)
            {
                log.DebugFormat("-- Failed retrieving item container from '{0}'", item);
                return(null);
            }

            var service = UIServiceProvider.GetService <ICellEnumerationService>(currentRow);

            log.DebugFormat("-- Found service provider {0}", service);

            //((IUIService)service).AttachToElement(currentRow);

            return(service);
        }
        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;
                }
            }
        }
Exemplo n.º 10
0
 private void ServiceProvider_FullyAttached(object obj, EventArgs args)
 {
     commandRegulator = UIServiceProvider.GetService <ICommandRegulationService>(dataGrid);
 }
Exemplo n.º 11
0
 public virtual void AttachToElement(FrameworkElement servedElement)
 {
     sharedObjectsService = UIServiceProvider.GetService <SharedObjectsService>(servedElement);
     element = servedElement;
 }