public MFTestResults UIElement_RaiseEvent_FocusChangedEvent_Test2() { MFTestResults testResult = MFTestResults.Pass; Log.Comment("Raising FocusChangedEventEvents and Verifying"); //addToEvtRoute = false; btnEvent = false; fcsEvent = true; _fcsEventCntr = 0; rEvents = new RoutedEvent[] { Buttons.GotFocusEvent, Buttons.LostFocusEvent }; for (int i = 0; i < rEvents.Length; i++) { mainWindow.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(AddToHandler), rEvents[i]); FocusChangedEventArgs fcea = new FocusChangedEventArgs(null, DateTime.Now, mainWindow, mainWindow); fcea.RoutedEvent = rEvents[i]; mainWindow.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(RaiseEvent), fcea); if (_fcsEventCntr != i + 1) { Log.Comment("FocusChangedEvent '" + rEvents[i].Name + "' event not raised"); testResult = MFTestResults.Fail; } } fcsEvent = false; return testResult; }
private void ChangeFocus(UIElement focus, DateTime timestamp) { if (focus != _focus) { // Update the critical pieces of data. UIElement oldFocus = _focus; _focus = focus; _focusRootUIElement = focus != null ? focus.RootUIElement : null; // Adjust the handlers we use to track everything. if (oldFocus != null) { oldFocus.IsEnabledChanged -= _isEnabledOrVisibleChangedEventHandler; oldFocus.IsVisibleChanged -= _isEnabledOrVisibleChangedEventHandler; } if (focus != null) { focus.IsEnabledChanged += _isEnabledOrVisibleChangedEventHandler; focus.IsVisibleChanged += _isEnabledOrVisibleChangedEventHandler; } // Send the LostFocus and GotFocus events. if (oldFocus != null) { FocusChangedEventArgs lostFocus = new FocusChangedEventArgs(this, timestamp, oldFocus, focus); lostFocus.RoutedEvent = Buttons.LostFocusEvent; lostFocus.Source = oldFocus; _inputManager.ProcessInput(lostFocus); } if (focus != null) { FocusChangedEventArgs gotFocus = new FocusChangedEventArgs(this, timestamp, oldFocus, focus); gotFocus.RoutedEvent = Buttons.GotFocusEvent; gotFocus.Source = focus; _inputManager.ProcessInput(gotFocus); } } }
object AddToHandler(object obj) { if (obj is RoutedEvent && btnEvent) { mainWindow.AddHandler((RoutedEvent)obj, new RoutedEventHandler(HandleButtonEvents), handledEventsToo); } if (obj is RoutedEvent && fcsEvent) { mainWindow.AddHandler((RoutedEvent)obj, new RoutedEventHandler(HandleFocusChangedEvent), handledEventsToo); } if (obj is EventRoute) { RoutedEventArgs args = null; if (btnEvent) { args = new ButtonEventArgs(null, null, DateTime.Now, Hardware.Button.AppDefined1); args.RoutedEvent = Buttons.ButtonDownEvent; } else { args = new FocusChangedEventArgs(null, DateTime.Now, mainWindow, mainWindow); args.RoutedEvent = Buttons.LostFocusEvent; } mainWindow.AddToEventRoute((EventRoute)obj, args); } return null; }
public MFTestResults UIElement_AddToEventRouteTest4() { MFTestResults testResult = MFTestResults.Pass; rEvents = new RoutedEvent[] { Buttons.ButtonDownEvent, Buttons.ButtonUpEvent, Buttons.PreviewButtonDownEvent, Buttons.PreviewButtonUpEvent}; handledEventsToo = false; //addToEvtRoute = true; Log.Comment("Setting Both Event Counters to zero (0)"); _btnEventCntr = 0; _fcsEventCntr = 0; Log.Comment("Adding all ButtonDownEvents to the EventRoute"); btnEvent = true; fcsEvent = false; for (int i = 0; i < rEvents.Length; i++) { eRoute = new EventRoute(rEvents[i]); mainWindow.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(AddToHandler), eRoute); } Log.Comment("Raising the Events and Verifying"); for (int i = 0; i < rEvents.Length; i++) { ButtonEventArgs bea = new ButtonEventArgs(null, null, DateTime.Now, Hardware.Button.AppDefined1); bea.RoutedEvent = rEvents[i]; mainWindow.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(RaiseEvent), bea); } Log.Comment("This currently fails, getting one additional button event than expected, investigating"); if (_btnEventCntr != rEvents.Length) { Log.Comment("Expected ButtonEvents = '" + rEvents.Length + "' but got '" + _btnEventCntr + "'"); testResult = MFTestResults.Skip; } Log.Comment("Adding all FocuseChangedEvents to the EventRoute"); btnEvent = false; fcsEvent = true; rEvents = new RoutedEvent[] { Buttons.GotFocusEvent, Buttons.LostFocusEvent }; for (int i = 0; i < rEvents.Length; i++) { eRoute = new EventRoute(rEvents[i]); mainWindow.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(AddToHandler), eRoute); } Log.Comment("Raising the Events and Verifying"); for (int i = 0; i < rEvents.Length; i++) { FocusChangedEventArgs fcea = new FocusChangedEventArgs(null, DateTime.Now, mainWindow, mainWindow); fcea.RoutedEvent = rEvents[i]; Application.Current.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(RaiseEvent), fcea); } if (_fcsEventCntr != rEvents.Length) { Log.Comment("Expected FocusChangedEvent = '" + rEvents.Length + "' but got '" + _fcsEventCntr + "'"); testResult = MFTestResults.Fail; } return testResult; }
/// <summary> /// An event announcing that the buttons is no longer focused on this element /// </summary> protected virtual void OnLostFocus(FocusChangedEventArgs e) { }
protected override void OnLostFocus(FocusChangedEventArgs e) { base.OnLostFocus(e); }
/// <summary> /// Focus event handler /// </summary> /// <param name="e"></param> protected override void OnGotFocus(FocusChangedEventArgs e) { // Whenever this window gets focus, it gives it to listbox Buttons.Focus(menuListBox); base.OnGotFocus(e); }
private static void OnLostFocusThunk(object sender, FocusChangedEventArgs e) { ((UIElement)sender).OnLostFocus(e); }