protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) { // If the IsVisible property changes... if (e.Property == IsVisibleProperty) { if (!(bool)e.NewValue) { // The menu is hiding so clear the current selection CurrentSelection = null; } // If the Menu is in a ContextMenu, ensure focus moves out of the context menu and into this Menu // after it is displayed... otherwise arrow keys won't work Dispatcher.BeginInvoke( DispatcherPriority.Send, (Action) (() => { var contextMenuParent = Keyboard.FocusedElement as ContextMenu; if (contextMenuParent != null && VisualTreeHelperExtended.GetAncestor(this, typeof(ContextMenu)) == contextMenuParent) { Focus(); } })); } base.OnPropertyChanged(e); }
/// <summary> /// Updates the focused <see cref="DataGridColumnHeader"/>. /// </summary> private static void UpdateFocusedHeader(DataGridControl datagrid) { if (null == datagrid) { return; } // Get the list of headers IList <DependencyObject> headers = VisualTreeHelperExtended.GetAllDescendants(datagrid, typeof(DataGridColumnHeader)); if (null == headers || 0 == headers.Count) { return; } // Update the focus based on the current tracking Modes FocusTrackingModes trackingModes = GetTrackingModes(datagrid); if (0 != (trackingModes & FocusTrackingModes.Headers)) { // Get the focused cell, if any, and look for an ancestor cell when editing cell DataGridCell cell = Keyboard.FocusedElement as DataGridCell; if (cell == null) { cell = VisualTreeHelperExtended.GetAncestor(Keyboard.FocusedElement as FrameworkElement, typeof(DataGridCell)) as DataGridCell; } // Update header focus, if any foreach (DataGridColumnHeader header in headers) { // Determine if the column associated with this header if focused bool isFocused = (null != cell && cell.Column == header.Column); // Update the focus for this header if (isFocused != GetIsFocusedHeader(header)) { if (isFocused) { header.SetValue(IsFocusedHeaderPropertyKey, true); } else { header.ClearValue(IsFocusedHeaderPropertyKey); } } } } else { // Clear header focus, if any foreach (DataGridColumnHeader header in headers) { if (GetIsFocusedHeader(header)) { header.ClearValue(IsFocusedHeaderPropertyKey); } } } }
///////////////////////////////////////////////////////////////////////////////////////////////////// // NON-PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Handles the <c>Click</c> event of the close button. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void OnCloseButtonClick(object sender, RoutedEventArgs e) { ZoomContentControl zoomContentControl = VisualTreeHelperExtended.GetAncestor(this, typeof(ZoomContentControl)) as ZoomContentControl; if (null != zoomContentControl) { zoomContentControl.Overlays.Remove(this); } }
/// <summary> /// Occurs when the <c>Layout.EvenlyDistributeToolsOnly</c> menu item is clicked. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param> private void OnLayoutEvenlyDistributeToolsOnlyMenuItemClick(object sender, RoutedEventArgs e) { var descendents = VisualTreeHelperExtended.GetAllDescendants <SplitContainer>(dockSite); if (descendents != null) { foreach (var splitContainer in descendents) { if (VisualTreeHelperExtended.GetAncestor <Workspace>(splitContainer) != null) { continue; } splitContainer.ResizeSlots(); } } }
private static void OnDataGridRowMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DataGridRow row = sender as DataGridRow; if (null == row) { return; } DataGridControl datagrid = VisualTreeHelperExtended.GetAncestor(row, typeof(DataGridControl)) as DataGridControl; if (null == datagrid) { return; } if (CollectionView.NewItemPlaceholder == row.Item) { ControlTemplate template = GetTemplate(datagrid); if (row.Template == template) { row.Template = GetDefaultTemplate(datagrid); row.UpdateLayout(); datagrid.CurrentItem = row.Item; // 3/23/2010 - Get the first non-read only column (http://www.actiprosoftware.com/Support/Forums/ViewForumTopic.aspx?ForumTopicID=4710) DataGridColumn column = datagrid.Columns.FirstOrDefault(col => !col.IsReadOnly); if (column != null) { DataGridCell cell = VisualTreeHelperExtended.GetAncestor(column.GetCellContent(row), typeof(DataGridCell)) as DataGridCell; if (cell != null) { cell.Focus(); } } datagrid.BeginEdit(); } } }
///////////////////////////////////////////////////////////////////////////////////////////////////// // COMMAND HANDLERS ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Occurs when the <see cref="RoutedCommand"/> is executed. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="e">An <see cref="ExecutedRoutedEventArgs"/> that contains the event data.</param> private void applicationExitCommand_Execute(object sender, ExecutedRoutedEventArgs e) { if (BrowserInteropHelper.IsBrowserHosted) { Page currentPage = (Page)VisualTreeHelperExtended.GetAncestor(this, typeof(Page)); if ((currentPage != null) && (currentPage.NavigationService.CanGoBack)) { currentPage.NavigationService.Navigate(Application.Current.StartupUri); } else { MessageBox.Show("Exit the application here."); } } else { Window window = (Window)ActiproSoftware.Windows.Media.VisualTreeHelperExtended.GetAncestor(ribbon, typeof(Window)); if (window != null) { window.Close(); } } }
///////////////////////////////////////////////////////////////////////////////////////////////////// #region COMMAND HANDLERS ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Occurs when the <see cref="RoutedCommand"/> is executed. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="e">An <see cref="ExecutedRoutedEventArgs"/> that contains the event data.</param> private static void OnToggleFrozenColumnExecute(object sender, ExecutedRoutedEventArgs e) { DataGridColumnHeader header = e.Parameter as DataGridColumnHeader; if (null != header) { DataGridControl datagrid = VisualTreeHelperExtended.GetAncestor(header, typeof(DataGridControl)) as DataGridControl; DataGridColumn column = header.Column; if (null != datagrid && null != column) { if (column.IsFrozen) { // Need to unfreeze column datagrid.FrozenColumnCount = column.DisplayIndex = datagrid.FrozenColumnCount - 1; } else { // Need to freeze column column.DisplayIndex = datagrid.FrozenColumnCount++; } } } }
///////////////////////////////////////////////////////////////////////////////////////////////////// // NON-PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Occurs when a tab is closing. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="e">A <see cref="AdvancedTabItemEventArgs"/> that contains the event data.</param> private void OnTabControlTabClosing(object sender, AdvancedTabItemEventArgs e) { var view = VisualTreeHelperExtended.GetAncestor <EditorView>(this); if (view == null) { return; } var tag = this.Tag as IntraLineViewportTag; if (tag == null) { return; } // Remove the tag IntraLineViewportTagger tagger = null; if (view.Properties.TryGetValue(typeof(IntraLineViewportTagger), out tagger)) { tagger.Remove(tag); } }
///////////////////////////////////////////////////////////////////////////////////////////////////// // NON-PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Called when <c>Validation.Error</c> is fired on the PropertyGrid or one it's descendents. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="ValidationErrorEventArgs"/> instance containing the event data.</param> private void OnPropertyGridValidationError(object sender, ValidationErrorEventArgs e) { switch (e.Action) { case ValidationErrorEventAction.Added: errorListBox.Items.Add(e.Error); // As a demonstration, show a dialog with the error message for property 'ErrorReporting3' var container = VisualTreeHelperExtended.GetAncestor <PropertyGridItem>(e.OriginalSource as DependencyObject); if (container != null) { var propertyModel = container.Content as IPropertyModel; if ((propertyModel != null) && (propertyModel.Name == "ErrorReporting3")) { MessageBox.Show(Convert.ToString(e.Error.ErrorContent, CultureInfo.CurrentCulture), "Data Validation", MessageBoxButton.OK, MessageBoxImage.Error); } } break; case ValidationErrorEventAction.Removed: errorListBox.Items.Add(e.Error); break; } }