private void Cell_LayoutUpdated( object sender, EventArgs e ) { if( !this.IsContainerPrepared || this.IsContainerVirtualized ) return; if( this.CurrentEditorPendingDisplayState == EditorDisplayState.PendingShow ) { //If the Cell is marked to be pending the display of the editor, then //this LayoutUpdated means that Editor has been effectively displayed // Notify the UIAutomation if any children have changed. AutomationPeer automationPeer = UIElementAutomationPeer.FromElement( this ); if( automationPeer != null ) { automationPeer.ResetChildrenCache(); } //Change the IsCellEditorDisplayed flag accordingly this.SetIsCellEditorDisplayed( true ); } else if( this.CurrentEditorPendingDisplayState == EditorDisplayState.PendingHide ) { //If the Cell is marked to be pending the Display of the viewer, then //this LayoutUpdated means that Editor has been effectively hidden // Notify the UIAutomation if any children have changed. AutomationPeer automationPeer = UIElementAutomationPeer.FromElement( this ); if( automationPeer != null ) { automationPeer.ResetChildrenCache(); } //Change the IsCellEditorDisplayed flag accordingly this.SetIsCellEditorDisplayed( false ); } // Reset the Editor/Viewer displaying flag. this.CurrentEditorPendingDisplayState = EditorDisplayState.None; // This condition allows detecting if the focus needs to be changed // after having displayed the editor. if( !this.IsCellEditorDisplayed || !this.FocusEditor ) return; // Reset the flag that indicates if the focus needs to be set in the template this.FocusEditor = false; bool editorFocused = false; DataGridContext dataGridContext = DataGridControl.GetDataGridContext( this ); DataGridControl dataGridControl = dataGridContext.DataGridControl; if( dataGridControl != null ) { //Focus need to be changed. editorFocused = dataGridControl.SetFocusHelper( this.ParentRow, this.ParentColumn, false, true ); } if( !editorFocused ) { m_keyGesture = null; m_textInputArgs = null; } else { //If a keystroke was recorded for "resend" upon layout update if( m_keyGesture != null ) { //Generate an EventArgs for the PreviewKeyDown for the KeyStroke Key realKey; if( ( m_keyGesture.Key == Key.None ) && ( m_keyGesture.SystemKey != Key.None ) ) { realKey = m_keyGesture.SystemKey; } else { realKey = m_keyGesture.Key; } try { KeyEventArgs kea = new KeyEventArgs( Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, realKey ); kea.RoutedEvent = Keyboard.PreviewKeyDownEvent; //send the event Keyboard.PrimaryDevice.FocusedElement.RaiseEvent( kea ); if( kea.Handled == false ) { //Generate an EventArgs for the KeyDown event Args for the preserved KeyStroke kea = new KeyEventArgs( Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, realKey ); kea.RoutedEvent = Keyboard.KeyDownEvent; //Send the Event to the Input Manager Keyboard.PrimaryDevice.FocusedElement.RaiseEvent( kea ); } } catch( SecurityException ex ) { //if the exception is for the UIPermission, then we want to suppress it if( !( ex.PermissionType.FullName == "System.Security.Permissions.UIPermission" ) ) { //not correct type, then rethrow the exception throw; } } //clear the KeyStroke preserved. m_keyGesture = null; } //If TextInput was preserved for resend if( m_textInputArgs != null ) { //Generate new TextInput Event Args TextCompositionEventArgs new_event = new TextCompositionEventArgs( m_textInputArgs.Device, m_textInputArgs.TextComposition ); new_event.RoutedEvent = UIElement.PreviewTextInputEvent; //Send the event to the InputManager. Keyboard.PrimaryDevice.FocusedElement.RaiseEvent( new_event ); if( !new_event.Handled ) { new_event = new TextCompositionEventArgs( m_textInputArgs.Device, m_textInputArgs.TextComposition ); new_event.RoutedEvent = UIElement.TextInputEvent; //Send the event to the InputManager. Keyboard.PrimaryDevice.FocusedElement.RaiseEvent( new_event ); } } //Clear the TextInput preserved. m_textInputArgs = null; } }
private void ShowEditTemplate() { if( m_delayedHideEditTemplateDispatcherOperation != null ) { System.Diagnostics.Debug.Assert( m_delayedHideEditTemplateDispatcherOperation.Status == DispatcherOperationStatus.Pending ); m_delayedHideEditTemplateDispatcherOperation.Abort(); m_delayedHideEditTemplateDispatcherOperation = null; } // The editor is not pending showing if( this.CurrentEditorPendingDisplayState != EditorDisplayState.PendingShow ) { // If it is not displayed or pending hiding if( !this.IsCellEditorDisplayed || ( this.CurrentEditorPendingDisplayState == EditorDisplayState.PendingHide ) ) { CellEditor cellEditor = this.GetCellEditor(); if( cellEditor != null ) { this.SetCoercedContentTemplate( this.GetCoercedCellContentTemplate(), cellEditor.EditTemplate ); // Force the editor to update its editor state on next layout pass this.CurrentEditorPendingDisplayState = EditorDisplayState.PendingShow; } } else { // This will force re-layout of the control, raising the LayoutUpdated event // and correctly update the display state for this editor this.InvalidateArrange(); } } }
private void HideEditTemplate() { m_delayedHideEditTemplateDispatcherOperation = null; // The Cell is not prepared or virtualized, no need to // hide the edit template since it will be refreshed // the the Cell is prepared again. if( !this.IsContainerPrepared || this.IsContainerVirtualized ) return; if( ( !this.IsCellEditorDisplayed ) && ( this.CurrentEditorPendingDisplayState != EditorDisplayState.PendingShow ) ) return; this.SetCoercedContentTemplate( this.GetCoercedCellContentTemplate(), null ); this.CurrentEditorPendingDisplayState = EditorDisplayState.PendingHide; // We must clear the CellEditorContext when the Template is hidden // to avoid side effects of the CellEditorBinding affecting null // in the source. The reason is that the CellEditorContext is the // binding source of the default foreign key CellEditor Template Cell.ClearCellEditorContext( this ); }
private void ShowEditTemplate() { this.AbortHideEditTemplate(); // The editor is not pending showing if( this.CurrentEditorPendingDisplayState != EditorDisplayState.PendingShow ) { // If it is not displayed or pending hiding if( !this.IsCellEditorDisplayed || ( this.CurrentEditorPendingDisplayState == EditorDisplayState.PendingHide ) ) { CellEditor cellEditor = this.GetCellEditor(); if( cellEditor != null ) { this.SetCoercedContentTemplate( this.GetCoercedCellContentTemplate(), cellEditor.EditTemplate ); // Force the editor to update its editor state on next layout pass this.CurrentEditorPendingDisplayState = EditorDisplayState.PendingShow; } } else { // This will force re-layout of the control, raising the LayoutUpdated event // and correctly update the display state for this editor this.InvalidateArrange(); } } }