protected virtual void ExecuteCore( ColumnBase column, int index )
    {
      var groupDescriptions = this.GroupDescriptions;
      if( groupDescriptions == null )
        return;

      GroupDescription groupDescription = this.GetGroupDescription( column );
      if( groupDescription == null )
      {
        groupDescription = new DataGridGroupDescription( this.GetColumnName( column ) );
      }

      var dataGridGroupDescription = groupDescription as DataGridGroupDescription;
      if( ( dataGridGroupDescription != null ) && ( dataGridGroupDescription.GroupConfiguration == null ) )
      {
        dataGridGroupDescription.GroupConfiguration = this.GetGroupConfiguration( column );
      }

      if( index < 0 )
      {
        groupDescriptions.Add( groupDescription );
      }
      else
      {
        groupDescriptions.Insert( index, groupDescription );
      }
    }
    public void Execute( ColumnBase column, int index )
    {
      if( !this.CanExecute( column, index ) )
        return;

      this.ExecuteCore( column, index );
    }
    public bool TryGetItemPropertyName( ColumnBase column, out string itemPropertyName )
    {
      if( column != null )
        return this.TryGetSource( column.FieldName, out itemPropertyName );

      itemPropertyName = null;

      return false;
    }
    public bool TryGetColumnFieldName( ColumnBase column, out string columnName )
    {
      if( column != null )
        return this.TryGetTarget( column.FieldName, out columnName );

      columnName = null;

      return false;
    }
예제 #5
0
    protected override void InitializeCore( DataGridContext dataGridContext, Row parentRow, ColumnBase parentColumn )
    {
      ColumnBase oldParentColumn = this.ParentColumn;

      base.InitializeCore( dataGridContext, parentRow, parentColumn );

      // This is a fix for Case 106982 (could not bind to XML datasources that contained namespaces).
      //
      // For an unknown reason, when a recycled DataCell was added back to the VisualTree (added
      // to the CellsHostPanel in its ParentRow), the binding would fail to update when the XPath
      // expression contained a namespace prefix, even if the XmlNamespaceManager property is inherited
      // and querying for the value of this property after adding the DataCell to the VTree would return
      // a valid, non-null XmlNamespaceManager.
      //
      // Forcing a local value for the XmlNamespaceManager property solves this problem, but it is
      // not the best thing to do as we are effectively bypassing the inheritance behavior for this
      // property...
      this.SetValue( Binding.XmlNamespaceManagerProperty, dataGridContext.DataGridControl.GetValue( Binding.XmlNamespaceManagerProperty ) );

      //prevent the setup of the display member binding more than once on the same column!
      if( ( !this.IsInternalyInitialized ) || ( oldParentColumn != parentColumn ) )
      {
        //call the helper function to setup the Cell's binding.
        this.SetupDisplayMemberBinding( dataGridContext );
      }
      else
      {

        BindingExpression binding = BindingOperations.GetBindingExpression( this, DataCell.ContentProperty );

        if( binding != null )
        {
          binding.UpdateTarget();
        }
      }
    }
예제 #6
0
 internal CellEditorContext( ColumnBase parentColumn, ForeignKeyConfiguration configuration )
 {
   this.SetParentColumn( parentColumn );
   this.SetForeignKeyConfiguration( configuration );
 } 
예제 #7
0
 private static void ApplySettingsRepositoryToColumn( ColumnBase column )
 {
 }
      private static KeyValuePair<DependencyProperty, BindingBase> CreateBinding( DependencyProperty dp, ColumnBase source )
      {
        if( dp == null )
          throw new ArgumentNullException( "property" );

        if( source == null )
          throw new ArgumentNullException( "source" );

        var binding = new Binding();
        binding.Path = new PropertyPath( dp );
        binding.Source = source;

        return new KeyValuePair<DependencyProperty, BindingBase>( dp, binding );
      }
      internal SynchronizationKey(
        ColumnBase masterColumn,
        ColumnBase detailColumn,
        DetailConfiguration detailConfig )
      {
        if( detailColumn == null )
          throw new ArgumentNullException( "detailColumn" );

        if( detailConfig == null )
          throw new ArgumentNullException( "detailConfig" );

        m_masterColumn = masterColumn;
        m_detailColumn = detailColumn;
        m_detailConfiguration = detailConfig;
      }
 public static void RemoveListener( ColumnBase source, IWeakEventListener listener )
 {
   CurrentManager.ProtectedRemoveListener( source, listener );
 }
    internal void DoResize( double newWidth, ColumnBase parentColumn )
    {
      if( !this.IsEnabled )
        return;

      if( !parentColumn.HasFixedWidth )
      {
        if( newWidth < MIN_WIDTH )
        {
          newWidth = MIN_WIDTH;
        }

        if( newWidth < parentColumn.MinWidth )
        {
          newWidth = parentColumn.MinWidth;
        }

        if( newWidth > parentColumn.MaxWidth )
        {
          newWidth = parentColumn.MaxWidth;
        }

        parentColumn.Width = newWidth;
      }
    }
    protected override void InitializeCore( DataGridContext dataGridContext, Row parentRow, ColumnBase parentColumn )
    {
      base.InitializeCore( dataGridContext, parentRow, parentColumn );

      this.SetColumnBinding( ColumnManagerCell.ContentProperty, parentColumn, ColumnBase.TitleProperty );
      this.SetColumnBinding( ColumnManagerCell.ContentTemplateProperty, parentColumn, ColumnBase.TitleTemplateProperty );
      this.SetColumnBinding( ColumnManagerCell.ContentTemplateSelectorProperty, parentColumn, ColumnBase.TitleTemplateSelectorProperty );
    }
        /// <summary>
        /// Show callout in proper position.
        /// </summary>
        /// <param name="column">Collumn with invalid property.</param>
        private void _InitCallout(ColumnBase column)
        {
            // Remember column with invalid property.
            _column = column;

            // Show callout in right place.
            _SetPopupPosition();
        }
        /// <summary>
        /// When mouse move in invalid cell - show corresponding popup.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        private void _dataGridMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            // Find cell on which mouse moved.
            Cell cell = XceedVisualTreeHelper.GetCellByEventArgs(e);

            // If cell has error, grid isnt in editing state and timer is running - show callout.
            if (cell != null && cell.HasValidationError && !_timer.IsEnabled &&
                 !_dataGrid.IsBeingEdited &&
                 !(_dataGrid.InsertionRow != null && _dataGrid.InsertionRow.IsBeingEdited))
            {
                _showCallout = true;

                // Detect current column and item. Show callout.
                IDataErrorInfo currentItem =
                    _dataGrid.GetItemFromContainer(cell) as IDataErrorInfo;

                var columns = _dataGrid.GetVisibleColumns();
                _column = columns.FirstOrDefault(x => x.FieldName == cell.FieldName);
                _InvalidItem = currentItem;
                _SetPopupPosition();

                _showCallout = false;

                // When mouse leave current cell - callout must be hided.
                cell.MouseLeave += new System.Windows.Input.MouseEventHandler(_MouseLeaveCellWithInvalidProperty);
            }
        }
예제 #15
0
 private void SetContentTemplateSelector( ColumnBase parentColumn )
 {
   Binding binding = new Binding();
   binding.Path = new PropertyPath( ColumnBase.TitleTemplateSelectorProperty );
   binding.Mode = BindingMode.OneWay;
   binding.Source = parentColumn;
   binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
   BindingOperations.SetBinding( this, ColumnManagerCell.ContentTemplateSelectorProperty, binding );
 }
 public static void RemoveListener( ColumnBase source, IWeakEventListener listener )
 {
   CellContentStringFormatChangedEventManager.CurrentManager.ProtectedRemoveListener( source, listener );
 }
예제 #17
0
    public void UpdateSelection(
      DataGridContext oldCurrentDataGridContext,
      object oldCurrentItem,
      ColumnBase oldCurrentColumn,
      DataGridContext dataGridContext,
      bool oldFocusWasInTheGrid,
      bool rowIsBeingEditedAndCurrentRowNotChanged,
      int sourceDataItemIndex,
      object item,
      int columnIndex,
      Nullable<UpdateSelectionSource> updateSelectionSourceParam )
    {
      int oldCurrentColumnIndex = ( oldCurrentColumn == null ) ? -1 : oldCurrentColumn.VisiblePosition;

      if( item == null )
        return;

      UpdateSelectionSource updateSelectionSource = ( updateSelectionSourceParam.HasValue )
        ? updateSelectionSourceParam.Value : m_currentUpdateSelectionSource;

      // Force the node tree to be created since detail can be deleted during that node creation and selection uptade will be call
      // That way we prevent selection code reentrance.
      this.EnsureNodeTreeCreatedOnAllSubContext( m_owner.DataGridContext );

      if( ( updateSelectionSource != UpdateSelectionSource.RowSelector )
          && ( updateSelectionSource != UpdateSelectionSource.MouseUp ) )
      {
        // Reset the fromRowSelector to ensure nothing special is done
        // on next MouseUp
        m_fromRowSelector = false;
      }

      if( updateSelectionSource == UpdateSelectionSource.None )
        return;

      this.Begin();

      try
      {
        switch( m_owner.SelectionModeToUse )
        {
          case SelectionMode.Single:
            {
              this.DoSingleSelection(
                dataGridContext, oldFocusWasInTheGrid, rowIsBeingEditedAndCurrentRowNotChanged,
                sourceDataItemIndex, item, columnIndex, updateSelectionSource );

              break;
            }

          case SelectionMode.Multiple:
            {
              this.DoMultipleSelection(
                dataGridContext, rowIsBeingEditedAndCurrentRowNotChanged,
                sourceDataItemIndex, item, columnIndex, updateSelectionSource );

              break;
            }

          case SelectionMode.Extended:
            {
              this.DoExtendedSelection(
                oldCurrentDataGridContext, oldCurrentItem, oldCurrentColumnIndex,
                dataGridContext, oldFocusWasInTheGrid, rowIsBeingEditedAndCurrentRowNotChanged,
                sourceDataItemIndex, item, columnIndex, updateSelectionSource );

              break;
            }
        }
      }
      finally
      {
        try
        {
          this.End( false, true, false );
        }
        catch( DataGridException )
        {
          // This is to swallow when selection is aborted
        }
      }
    }
    private void SetColumnBinding( DependencyProperty targetProperty, ColumnBase parentColumn, DependencyProperty sourceProperty )
    {
      if( this.HasColumnBinding( targetProperty, parentColumn, sourceProperty ) )
        return;

      var binding = ColumnManagerCell.CreateColumnBinding( parentColumn, sourceProperty );
      if( binding != null )
      {
        BindingOperations.SetBinding( this, targetProperty, binding );
      }
      else
      {
        BindingOperations.ClearBinding( this, targetProperty );
      }
    }
예제 #19
0
    protected override Cell CreateCell( ColumnBase column )
    {
      if( column == null )
        throw new DataGridInternalException();

      return new DataCell();
    }
    private bool HasColumnBinding( DependencyProperty targetProperty, ColumnBase parentColumn, DependencyProperty sourceProperty )
    {
      if( parentColumn == null )
        return false;

      var binding = BindingOperations.GetBinding( this, targetProperty );
      if( binding == null )
        return false;

      var path = binding.Path;
      if( path == null )
        return false;

      var pathParameters = path.PathParameters;

      return ( binding.Source == parentColumn )
          && ( pathParameters.Count == 1 )
          && ( pathParameters[ 0 ] == sourceProperty );
    }
 protected override Cell CreateCell( ColumnBase column )
 {
   return new ColumnManagerCell();
 }
    private static Binding CreateColumnBinding( ColumnBase parentColumn, DependencyProperty sourceProperty )
    {
      if( parentColumn == null )
        return null;

      var binding = new Binding();
      binding.Path = new PropertyPath( sourceProperty );
      binding.Mode = BindingMode.OneWay;
      binding.Source = parentColumn;
      binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;

      return binding;
    }
 private static IEnumerable<KeyValuePair<DependencyProperty, BindingBase>> CreateBindings( ColumnBase source )
 {
   yield return BoundColumn.CreateBinding( ColumnBase.WidthProperty, source );
   yield return BoundColumn.CreateBinding( ColumnBase.MinWidthProperty, source );
   yield return BoundColumn.CreateBinding( ColumnBase.MaxWidthProperty, source );
   yield return BoundColumn.CreateBinding( ColumnBase.DesiredWidthProperty, source );
   yield return BoundColumn.CreateBinding( ColumnBase.VisibleProperty, source );
   yield return BoundColumn.CreateBinding( ColumnReorderingDragSourceManager.AnimatedColumnReorderingTranslationProperty, source );
   yield return BoundColumn.CreateBinding( TableflowView.IsBeingDraggedAnimatedProperty, source );
   yield return BoundColumn.CreateBinding( TableflowView.ColumnReorderingDragSourceManagerProperty, source );
 }
예제 #24
0
 internal bool SetFocusHelper(
   UIElement itemContainer,
   ColumnBase column,
   bool forceFocus,
   bool preserveEditorFocus )
 {
   return this.SetFocusHelper( itemContainer,
     column,
     forceFocus,
     preserveEditorFocus,
     false );
 }
예제 #25
0
    public static void CleanUpColumns( ColumnCollection columns, bool deleteAutoCreatedColumn )
    {
      ColumnBase[] tempColumns = new ColumnBase[ columns.Count ];
      columns.CopyTo( tempColumns, 0 );

      foreach( ColumnBase column in tempColumns )
      {
        Column dataColumn = column as Column;

        if( dataColumn == null )
          continue;

        if( ( deleteAutoCreatedColumn ) && ( dataColumn.IsAutoCreated ) )
        {
          columns.Remove( column );
        }
        else if( dataColumn.IsBindingAutoCreated )
        {
          // Disable warning for DisplayMemberBinding when internaly used
#pragma warning disable 618

          //clear the display member binding.
          dataColumn.DisplayMemberBinding = null;

#pragma warning restore 618

          dataColumn.IsBindingAutoCreated = false;
          dataColumn.IsBoundToDataGridUnboundItemProperty = false;
        }
      }
    }
예제 #26
0
    internal bool SetFocusHelper(
      UIElement itemContainer,
      ColumnBase column,
      bool forceFocus,
      bool preserveEditorFocus,
      bool preventMakeVisibleIfCellFocused )
    {
      if( m_inhibitSetFocus != 0 )
        return false;

      if( itemContainer == null )
        return false;

      //There is an identified weakness with the IsKeyboardFocusWithin property where it cannot tell if the focus is within a Popup which is within the element
      //This has been identified, and only the places where it caused problems were fixed... This comment is only here to remind developpers of the flaw
      if( ( !this.IsKeyboardFocusWithin ) && ( !this.IsKeyboardFocused ) && ( !forceFocus ) )
        return false;

#if DEBUG
      DataGridContext itemContainerDataGridContext = DataGridControl.GetDataGridContext( itemContainer );
      Debug.Assert( itemContainerDataGridContext != null );
      Debug.Assert( ( column == null ) || ( itemContainerDataGridContext.Columns.Contains( column ) ) );
#endif

      UIElement toFocus = null;

      Row row = Row.FromContainer( itemContainer );

      IDisposable preventMakeVisibleDisposable = null;

      try
      {
        if( row != null )
        {
          Cell cell = row.Cells[ column ];

          // The Cell must be in VisualTree to be able to get
          // the focus, else, .Focus() will always return false
          if( cell != null )
          {
            cell.EnsureInVisualTree();

            if( preventMakeVisibleIfCellFocused )
              preventMakeVisibleDisposable = cell.InhibitMakeVisible();
          }

          if( ( row.IsBeingEdited ) && ( cell != null ) )
          {
            if( ( cell.IsBeingEdited ) && ( preserveEditorFocus ) )
            {
              //Obtain the CellEditor's Focus Scope
              toFocus = Cell.GetCellFocusScope( cell );

              //If there was none defined
              if( toFocus == null )
              {
                //obtain the first focusable child into the template
                toFocus = DataGridControl.FindFirstFocusableChild( cell );
              }
            }

            if( toFocus == null )
            {
              toFocus = cell;
            }

            bool currentFocusIsInsideCell =
              ( cell != Keyboard.FocusedElement )
              && ( TreeHelper.IsDescendantOf( Keyboard.FocusedElement as DependencyObject, cell ) );

            //if the focus is already within the Cell to focus, then don't touch a thing
            if( ( currentFocusIsInsideCell ) && ( preserveEditorFocus ) && ( cell.IsBeingEdited ) )
            {
              //that means that the item to focus should be the Keyboard focused element

              // Already focused
              return true;
            }
          }
          else if( ( row.NavigationBehavior == NavigationBehavior.RowOnly ) || ( cell == null ) )
          {
            toFocus = row.RowFocusRoot;

            if( toFocus == null )
            {
              toFocus = row;
            }

            if( ( row.NavigationBehavior == NavigationBehavior.RowOrCell ) && ( row.IsSelected ) )
            {
              toFocus.Focusable = true;
            }
          }
          else
          {
            toFocus = cell;

            bool currentFocusIsInsideCell =
              ( cell != Keyboard.FocusedElement )
              && ( TreeHelper.IsDescendantOf( Keyboard.FocusedElement as DependencyObject, cell ) );

            //if the focus is already within the Cell to focus, then don't touch a thing
            if( ( currentFocusIsInsideCell ) && ( preserveEditorFocus ) )
            {
              // That means that the item to focus should be the Keyboard focused element
              // Already focused
              return true;
            }
          }
        }
        else
        {
          toFocus = itemContainer;

          //if the container for the item is not a Row, and the focus is already within that item
          //then don't touch the focus.
          bool partOfContainer = TreeHelper.IsDescendantOf( Keyboard.FocusedElement as DependencyObject, toFocus );

          if( partOfContainer )
          {
            // Already focused
            return true;
          }
        }

        return DataGridControl.SetFocusUIElementHelper( toFocus );
      }
      finally
      {
        if( preventMakeVisibleDisposable != null )
        {
          preventMakeVisibleDisposable.Dispose();
          preventMakeVisibleDisposable = null;
        }
      }
    }
 public ColumnActualWidthChangedEventArgs( ColumnBase column , double oldValue, double newValue )
 {
   m_column = column;
   m_oldValue = oldValue;
   m_newValue = newValue;
 }
    internal static void ToggleColumnSort(
      DataGridContext dataGridContext,
      SortDescriptionCollection sortDescriptions,
      ColumnCollection columns,
      ColumnBase column,
      bool shiftUnpressed )
    {
      if( column == null )
        throw new ArgumentNullException( "column" );

      Debug.Assert( ( dataGridContext != null ) || ( column.ParentDetailConfiguration != null ) );

      if( ( dataGridContext == null ) && ( column.ParentDetailConfiguration == null ) )
        throw new DataGridInternalException( "DataGridContext or ParentDetailConfiguration can't be null." );

      DataGridContext parentDataGridContext = ( dataGridContext == null ) ? null : dataGridContext.ParentDataGridContext;

      // Defer the RestoreState of each DataGridContext of the same level
      // to ensure all the DataGridContext will be correctly restored once
      // all of them are completely resorted
      HashSet<IDisposable> deferRestoreStateDisposable = new HashSet<IDisposable>();

      if( parentDataGridContext != null )
      {
        foreach( DataGridContext childContext in parentDataGridContext.GetChildContexts() )
        {
          deferRestoreStateDisposable.Add( childContext.DeferRestoreState() );
        }
      }

      IDisposable deferResortHelper = ( dataGridContext == null ) ? null :
        SortingHelper.DeferResortHelper( dataGridContext.ItemsSourceCollection, dataGridContext.Items, sortDescriptions );

      //this will ensure that all DataGridCollectionViews mapped to this SortDescriptions collection will only refresh their sorting once!
      SortDirection newSortDirection = column.SortDirection;
      if( ( shiftUnpressed ) &&
          ( ( column.SortIndex == -1 ) || ( sortDescriptions.Count > 1 ) ) )
        sortDescriptions.Clear();

      switch( newSortDirection )
      {
        case SortDirection.None:
          newSortDirection = SortDirection.Ascending;
          break;
        case SortDirection.Ascending:
          newSortDirection = SortDirection.Descending;
          break;

        case SortDirection.Descending:
          newSortDirection = SortDirection.None;
          break;
      }

      SortingHelper.ApplyColumnSort( dataGridContext, sortDescriptions, columns, column, newSortDirection );

      if( deferResortHelper != null )
      {
        //end of the DeferResort(), any DataGridCollectionView listening to the SortDescriptions instance will refresh its sorting!
        deferResortHelper.Dispose();
      }

      foreach( IDisposable disposable in deferRestoreStateDisposable )
      {
        try
        {
          // Try/Catch to ensure all contexts are restored
          disposable.Dispose();
        }
        catch( Exception )
        {
        }
      }

      deferRestoreStateDisposable.Clear();
    }
예제 #29
0
 private void SetParentColumn( ColumnBase value )
 {
   this.SetValue( CellEditorContext.ParentColumnPropertyKey, value );
 }
    private static void ApplyColumnSort( DataGridContext dataGridContext, SortDescriptionCollection sortDescriptions, ColumnCollection columns, ColumnBase column, SortDirection sortDirection )
    {
      if( column == null )
        throw new ArgumentNullException( "column" );

      Debug.Assert( ( dataGridContext != null ) || ( column.ParentDetailConfiguration != null ) );

      if( ( dataGridContext == null ) && ( column.ParentDetailConfiguration == null ) )
        throw new DataGridInternalException( "DataGridContext or ParentDetailConfiguration cannot be null." );

      if( !columns.Contains( column ) )
        throw new ArgumentException( "The specified column is not part of the DataGridContext.", "column" );

      string fieldName = column.FieldName;

      bool canSort = ( dataGridContext != null ) ? dataGridContext.Items.CanSort : true;

      if( ( !string.IsNullOrEmpty( fieldName ) ) && ( canSort == true ) )
      {
        SortDescription existingSort;
        int sortDescriptionIndex = sortDescriptions.Count;

        for( int i = sortDescriptions.Count - 1; i >= 0; i-- )
        {
          existingSort = sortDescriptions[ i ];

          if( existingSort.PropertyName == fieldName )
          {
            if( ( ( existingSort.Direction == ListSortDirection.Ascending ) && ( sortDirection == SortDirection.Ascending ) ) ||
                ( ( existingSort.Direction == ListSortDirection.Descending ) && ( sortDirection == SortDirection.Descending ) ) )
            {
              // Nothing to change!
              sortDescriptionIndex = -1;
            }
            else
            {
              sortDescriptionIndex = i;
              sortDescriptions.Remove( existingSort );
            }

            break;
          }
        }

        int maxDescriptions = ( dataGridContext != null ) ? dataGridContext.MaxSortLevels 
          : column.ParentDetailConfiguration.MaxSortLevels;

        if( ( maxDescriptions != -1 ) && ( sortDescriptions.Count >= maxDescriptions ) )
        {
          // Cannot insert sort description since it would go beyond the max sort description count.
          sortDescriptionIndex = -1;
          sortDirection = SortDirection.None;
        }

        if( ( sortDescriptionIndex > -1 ) && ( sortDirection != SortDirection.None ) )
        {
          SortDescription sortDescription = new SortDescription( fieldName,
            ( sortDirection == SortDirection.Ascending ) ? ListSortDirection.Ascending : ListSortDirection.Descending );

          sortDescriptions.Insert( sortDescriptionIndex, sortDescription );
          column.SetSortIndex( sortDescriptionIndex );
          column.SetSortDirection( sortDirection );
        }

        SortingHelper.SynchronizeSortIndexes( sortDescriptions, columns );
      }
    }