Ejemplo n.º 1
0
 public UpdateSelectionSourceHelper(
   SelectionManager selectionManager,
   UpdateSelectionSource newUpdateSelectionSource )
 {
   m_selectionManager = selectionManager;
   m_oldUpdateSelectionSource = selectionManager.m_currentUpdateSelectionSource;
   selectionManager.m_currentUpdateSelectionSource = newUpdateSelectionSource;
 }
Ejemplo n.º 2
0
    public DataGridControl()
    {
      m_selectionChangerManager = new SelectionManager( this );

      this.SetValue( DataGridControl.ParentDataGridControlPropertyKey, this );

      //set the FixedItem for the gridControl to NotSet, this is to prevent problems with nested DataGridControls
      DataGridControl.SetFixedItem( this, DataGridControl.NotSet );

      this.SetDetailConfigurations( new DetailConfigurationCollection( this, null ) );

      this.DetailConfigurations.CollectionChanged += this.OnDetailConfigurationsChanged;

      this.CommandBindings.Add( new CommandBinding( DataGridCommands.ExpandGroup, this.OnExpandGroupExecuted, this.OnExpandGroupCanExecute ) );

      this.CommandBindings.Add( new CommandBinding( DataGridCommands.CollapseGroup, this.OnCollapseGroupExecuted, this.OnCollapseGroupCanExecute ) );

      this.CommandBindings.Add( new CommandBinding( DataGridCommands.ToggleGroupExpansion, this.OnToggleGroupExecuted, this.OnToggleGroupCanExecute ) );

      this.CommandBindings.Add( new CommandBinding( ApplicationCommands.SelectAll, this.OnSelectAllExecuted, this.OnSelectAllCanExecute ) );

      this.CommandBindings.Add( new CommandBinding( DataGridCommands.ClearFilter, this.OnClearFilterExecuted ) );

      // We keep a references to be able to remove the CommandBindings when they are not required (feature disabled)
      m_refreshCommandBinding = new CommandBinding( DataGridCommands.Refresh, this.OnRefreshExecuted, this.OnRefreshCanExecute );
      this.CommandBindings.Add( m_refreshCommandBinding );

      // We keep a references to be able to remove the CommandBindings when they are not required (feature disabled)
      m_copyCommandBinding = new CommandBinding( ApplicationCommands.Copy, this.OnCopyExecuted, this.OnCopyCanExecute );
      this.CommandBindings.Add( m_copyCommandBinding );

      // The delete command is not enabled by default, so don't add it to CommandBindings
      m_deleteCommandBinding = new CommandBinding( ApplicationCommands.Delete, this.OnDeleteExecuted, this.OnDeleteCanExecute );

      DataGridContext dataGridContext = new DataGridContext( null, this, null, this.Items, null );
      m_customItemContainerGenerator = CustomItemContainerGenerator.CreateGenerator( this, this.Items, dataGridContext );
      m_customItemContainerGenerator.DetailsChanged += OnDetailsChanged;

      DataGridControl.SetDataGridContext( this, dataGridContext );
      m_localDataGridContext = dataGridContext;

      //so that at least one DataGridContext is always current
      dataGridContext.SetIsCurrentHelper( true );
      this.SetCurrentDataGridContextHelper( dataGridContext );

      this.SetValue( DataGridControl.ColumnsPropertyKey, dataGridContext.Columns );
      this.SetValue( DataGridControl.VisibleColumnsPropertyKey, dataGridContext.VisibleColumns );
      this.SetValue( DataGridControl.GroupLevelDescriptionsPropertyKey, dataGridContext.GroupLevelDescriptions );
      this.SetValue( DataGridControl.SelectedItemsPropertyKey, dataGridContext.SelectedItems );
      this.SetValue( DataGridControl.SelectedItemRangesPropertyKey, new SelectionItemRangeCollection( dataGridContext.SelectedItemsStore ) );
      this.SetValue( DataGridControl.SelectedCellRangesPropertyKey, new SelectionCellRangeCollection( dataGridContext.SelectedCellsStore ) );

      // Apparently, we don't need to unsubscribe from these event handlers. These event 
      // subscriptions do not "root" the grid and we observed no leak cause be these.
      // We did not investigate why that is and we should keep an eye on it.
      this.GroupStyle.CollectionChanged += new NotifyCollectionChangedEventHandler( GroupStyle_CollectionChanged );


      if( DesignerProperties.GetIsInDesignMode( this ) )
      {
        // Workaround for VS2008's know issue (the DataGrid's Template is not active).
        // TODO (case 117288): Remove when the issue will be corrected.
        this.ClipToBounds = true;
      }

      this.Loaded += new RoutedEventHandler( DataGridControl_Loaded );
      this.LayoutUpdated += new EventHandler( DataGridControl_LayoutUpdated );
    }