private void DataGridEditingExtender_PreviewCurrentChanging(object sender, PreviewChangeEventArgs e) { UniversalCellInfo oldCell = (UniversalCellInfo)(e.OldValue ?? new UniversalCellInfo()); UniversalCellInfo newCell = (UniversalCellInfo)(e.NewValue ?? new UniversalCellInfo()); var focusManager = UIServiceProvider.GetService <IFocusManagementService>(TargetElement); using (focusManager.DeferFocusUpdate()) { if (!CanLeaveCurrentCell()) { CancelNavigation(e); } else if (oldCell.Item != newCell.Item) { log.DebugFormat("Processing line change event on {0}", this); if (!CanLeaveCurrentLine()) { CancelNavigation(e); } } } }
protected override void Cleanup() { EditMode.TargetElement.RemoveHandler(FrameworkElement.PreviewKeyDownEvent, (RoutedEventHandler)TargetElement_PreviewKeyDown); EditMode.TargetElement.RemoveHandler(FrameworkElement.PreviewKeyUpEvent, (RoutedEventHandler)TargetElement_PreviewKeyUp); currentCellService = UIServiceProvider.GetService <ICurrentCellService>(EditMode.TargetElement); currentCellService.CurrentCellChanged -= currentCellService_CurrentCellChanged; }
private void RegisterKeyGesture(Key key, Action <KeyEventArgs> action) { InputService inputService = UIServiceProvider.GetService <InputService>(TargetElement); var gesture = new KeyGesture(key); registeredGestures.Add(gesture); inputService.RegisterKeyGestureAction(gesture, action); }
public virtual void Setup() { CurrentCellService = UIServiceProvider.GetService <ICurrentCellService>(TargetElement); CommandRegulator = UIServiceProvider.GetService <ICommandRegulationService>(TargetElement); CommandRegulator.PreviewCanExecute += PreviewCanExecuteCommand; CurrentCellService.PreviewCurrentCellChanging += DataGridEditingExtender_PreviewCurrentChanging; }
protected override void Setup() { EditMode.TargetElement.AddHandler(FrameworkElement.PreviewKeyDownEvent, (RoutedEventHandler)TargetElement_PreviewKeyDown, true); EditMode.TargetElement.AddHandler(FrameworkElement.PreviewKeyUpEvent, (RoutedEventHandler)TargetElement_PreviewKeyUp, true); currentCellService = UIServiceProvider.GetService <ICurrentCellService>(EditMode.TargetElement); currentCellService.CurrentCellChanged += currentCellService_CurrentCellChanged; currentCellService.PreviewCurrentCellChanging += currentCellService_PreviewCurrentCellChanging; }
private void CancelEdit(KeyEventArgs e) { var editStateService = UIServiceProvider.GetService <IElementEditStateService>(TargetElement); if (editStateService.IsEditingField) { editStateService.CancelItemEdit(); } e.Handled = true; }
protected override bool CanLeaveCurrentLine() { var editStateService = UIServiceProvider.GetService <IElementEditStateService>(TargetElement); if (editStateService.IsEditingField) { return(editStateService.CommitItemEdit()); } return(true); }
public override void Cleanup() { base.Cleanup(); InputService inputService = UIServiceProvider.GetService <InputService>(TargetElement); foreach (var gesture in registeredGestures) { inputService.UnregisterGestureAction(gesture); } }
private void ToggleEdit(KeyEventArgs e) { var editStateService = UIServiceProvider.GetService <IElementEditStateService>(TargetElement); if (editStateService.IsEditingField) { editStateService.CommitItemEdit(); } else { editStateService.BeginItemEdit(); } e.Handled = true; }
private void MoveToNextState() { TargetElement.Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(() => { var fms = UIServiceProvider.GetService <IFocusManagementService>(TargetElement); using (fms.DeferFocusUpdate()) { log.Debug("Moving to next edit state"); EditModeState nextState = currentState.GetNextState(); currentState.Leave(); currentState = nextState; currentState.Enter(this); } })); }
public SelectionModeManager(FrameworkElement element) { ElementSelectionService = UIServiceProvider.GetService <IMultiSelectionService>(element); CurrentItemTracker = UIServiceProvider.GetService <ICurrentItemService>(element); CurrentItemTracker.CurrentChanged += CurrentItemTracker_CurrentChanged; //ElementSelectionService.AddHandler(FrameworkElement.PreviewKeyDownEvent, new RoutedEventHandler(TargetElement_PreviewKeyDown), true); //ElementSelectionService.AddHandler(FrameworkElement.PreviewKeyUpEvent, new RoutedEventHandler(TargetElement_PreviewKeyUp), true); //ElementSelectionService.AddHandler(FrameworkElement.PreviewMouseDownEvent, new RoutedEventHandler(TargetElement_PreviewMouseDown), true); SingleSelectionMode.Initialize(ElementSelectionService, CurrentItemTracker); MultiSelectionMode.Initialize(ElementSelectionService, CurrentItemTracker); SetCurrentSelectionMode(SingleSelectionMode); currentSelectionMode.Enter(); }
public override void Enter() { var anchor = CurrentItemTracker.CurrentItem; if (ElementSelectionService.SelectedItem != null) { anchor = ElementSelectionService.SelectedItem; } log.Debug("Entering multi-selection mode."); log.DebugFormat("Anchor is {0}", anchor); lastKnownCurrentItem = anchor; lastDistanceFromSelectionAnchor = 0; var inputService = UIServiceProvider.GetService <InputService>(ElementSelectionService.Element); inputService.RegisterKeyGestureAction(ToggleSelectionKey, (a) => ToggleItemSelection()); }
protected override bool CanLeaveCurrentCell() { if (EditStateService.IsEditingField) { var fms = UIServiceProvider.GetService <IFocusManagementService>(TargetElement); deferedFocus.Push(fms.DeferFocusUpdate()); log.Debug("Leaving current cell: Commit"); if (EditStateService.CommitFieldEdit()) { return(true); } else { DisposeDeferedFocus(); return(false); } } return(true); }
public bool BeginFieldEdit() { if (!canBeginEdit) { return(false); } var currentCellService = UIServiceProvider.GetService <ICurrentCellService>(CellContainerOwner); editingCell = currentCellService.CurrentCellContainer as VirtualTableCell; if (editingCell != null) { if (editingCell.BeginEdit()) { OnEditStateChanged(); return(true); } } return(false); }
public void SetServiceProviderTest() { // Open a window with a control without any service. Window window = new Window(); Button button = new Button(); window.Content = button; using (TestUtils.AutoCloseWindow(window)) { var serviceList = UIServiceProvider_Accessor.GetServiceList(button); Assert.IsNotNull(serviceList); List <IUIServiceFactory> serviceListWrapper = new List <IUIServiceFactory>(serviceList); Assert.AreEqual(0, serviceListWrapper.Count); Assert.IsNull(UIServiceProvider_Accessor.GetServiceProvider(button)); var service = UIServiceProvider.GetService(button, typeof(TestServiceBase)); Assert.IsNull(service); } // Open a window with a control that has services attached. window = new Window(); button = new Button(); window.Content = button; UIServiceCollection serviceCollection = new UIServiceCollection(); var serviceA = new TestServiceA(); serviceCollection.Add(new ServiceFactoryMock(serviceA)); UIServiceProvider.SetServiceList(button, serviceCollection); using (TestUtils.AutoCloseWindow(window)) { Assert.IsNotNull(UIServiceProvider_Accessor.GetServiceList(button)); Assert.IsNotNull(UIServiceProvider_Accessor.GetServiceProvider(button)); var service = UIServiceProvider.GetService(button, typeof(TestServiceBase)); Assert.IsInstanceOfType(service, typeof(TestServiceA)); Assert.IsFalse(serviceA.IsDisposed); } Assert.IsTrue(serviceA.IsDisposed); }
public override void Leave() { var inputService = UIServiceProvider.GetService <InputService>(ElementSelectionService.Element); inputService.UnregisterGestureAction(ToggleSelectionKey); }