private static void OnNotifyDetailsTemplatePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DataGridRow row = (DataGridRow)d; row.NotifyPropertyChanged(row, e, NotificationTarget.Rows | NotificationTarget.DetailsPresenter); // It only makes sense to fire UnloadingRowDetails if the row details are already loaded. The same is true for LoadingRowDetails, // since making row details visible will take care of firing LoadingRowDetails. if (row.DetailsLoaded && d.GetValue(e.Property) == e.NewValue) { if (row.DataGridOwner != null) { row.DataGridOwner.OnUnloadingRowDetailsWrapper(row); } if (e.NewValue != null) { // Invoke LoadingRowDetails, but only after the details template is expanded (so DetailsElement will be available). Dispatcher.CurrentDispatcher.BeginInvoke(new DispatcherOperationCallback(DataGrid.DelayedOnLoadingRowDetails), DispatcherPriority.Loaded, row); } } }
private static void OnIsSelectedChanged(object sender, DependencyPropertyChangedEventArgs e) { DataGridRow row = (DataGridRow)sender; bool isSelected = (bool)e.NewValue; if (isSelected && !row.IsSelectable) { throw new InvalidOperationException(SR.Get(SRID.DataGridRow_CannotSelectRowWhenCells)); } DataGrid grid = row.DataGridOwner; if (grid != null && row.DataContext != null) { DataGridAutomationPeer gridPeer = UIElementAutomationPeer.FromElement(grid) as DataGridAutomationPeer; if (gridPeer != null) { DataGridItemAutomationPeer rowItemPeer = gridPeer.GetOrCreateItemPeer(row.DataContext); if (rowItemPeer != null) { rowItemPeer.RaisePropertyChangedEvent( System.Windows.Automation.SelectionItemPatternIdentifiers.IsSelectedProperty, (bool)e.OldValue, isSelected); } } } // Update the header's IsRowSelected property row.NotifyPropertyChanged(row, e, NotificationTarget.Rows | NotificationTarget.RowHeaders); // This will raise the appropriate selection event, which will // bubble to the DataGrid. The base class Selector code will listen // for these events and will update SelectedItems as necessary. row.RaiseSelectionChangedEvent(isSelected); }