1
ļ»æ// Copyright Ā© Microsoft Corporation.
2
// This source is subject to the Microsoft Source License for Silverlight Controls (March 2008 Release).
3
// Please see http://go.microsoft.com/fwlink/?LinkID=111693 for details.
4
// All other rights reserved.
6
using System.Diagnostics;
8
namespace System.Windows.Controlsb1
10
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1036:OverrideMethodsOnComparableTypes", Justification="IComparable in Jolt has only one method, probably a false positive in FxCop.")]
11
public abstract class DataGridColumnBase : /* DependencyObject,*/ IComparable<DataGridColumnBase>
15
private const byte DATAGRIDCOLUMN_defaultMinWidth = 0;
16
internal const int DATAGRIDCOLUMN_maximumWidth = 65536;
17
internal const byte DATAGRIDCOLUMN_minMinWidth = 2;
23
private Style _cellStyle; //
24
private int _displayIndex;
25
private object _header;
26
private DataGridColumnHeader _headerCell;
27
private Style _headerStyle; //
28
private bool _isFrozen;
29
private bool _isReadOnly;
30
private Visibility _visibility;
38
protected DataGridColumnBase()
40
this._visibility = Visibility.Visible;
41
this.MinWidth = DATAGRIDCOLUMN_defaultMinWidth;
42
this._displayIndex = -1;
45
#region IComparable<DataGridColumnBase> Implementation
47
public int CompareTo(DataGridColumnBase other)
49
return this._displayIndex - other._displayIndex;
52
#endregion IComparable<DataGridColumnBase> Implementation
54
#region Dependency Properties
363
#region Public Properties
366
public Style CellStyle
374
if (_cellStyle != value)
377
if (this.OwningGrid != null)
379
this.OwningGrid.OnColumnCellStyleChanged(this);
385
public bool? CanUserResize
392
public Style HeaderStyle
400
if (_headerStyle != value)
402
_headerStyle = value;
403
this.HeaderCell.Style = value;
408
public int DisplayIndex
412
return this._displayIndex;
416
if (this._displayIndex != value)
418
if (value == Int32.MaxValue)
420
throw DataGridError.DataGrid.ValueMustBeLessThan("value", "DisplayIndex", Int32.MaxValue);
422
if (this.OwningGrid != null)
424
if (value < 0 || value >= this.OwningGrid.Columns.Count)
426
throw DataGridError.DataGrid.ValueMustBeBetween("value", "DisplayIndex", 0, true, this.OwningGrid.Columns.Count, false);
428
// Will throw an error if a visible frozen column is placed inside a non-frozen area or vice-versa.
429
this.OwningGrid.OnColumnDisplayIndexChanging(this, value);
430
this._displayIndex = value;
433
this.OwningGrid.InDisplayIndexAdjustments = true;
434
this.OwningGrid.OnColumnDisplayIndexChanged_PreNotification();
435
this.OwningGrid.OnColumnDisplayIndexChanged(this);
436
this.OwningGrid.OnColumnDisplayIndexChanged_PostNotification();
440
this.OwningGrid.InDisplayIndexAdjustments = false;
447
throw DataGridError.DataGrid.ValueMustBeGreaterThanOrEqualTo("value", "DisplayIndex", -1);
449
this._displayIndex = value;
463
if (this._header != value)
465
this._header = value;
466
if (this._headerCell != null)
468
this._headerCell.Content = this._header;
480
public bool IsReadOnly
484
if (this.OwningGrid == null)
486
return this._isReadOnly;
488
return this.OwningGrid.GetColumnReadOnlyState(this, this._isReadOnly);
492
if (value != this.IsReadOnly)
494
if (this.OwningGrid != null)
496
this.OwningGrid.OnColumnReadOnlyStateChanging(this, value);
498
this._isReadOnly = value;
509
public double MinWidth
513
return this.InheritedMinWidth;
517
if (this.LocalMinWidth != value)
519
if (value < DATAGRIDCOLUMN_minMinWidth && value != 0)
521
throw DataGridError.DataGrid.ValueMustBeGreaterThanOrEqualTo("value", "MinWidth", DATAGRIDCOLUMN_minMinWidth);
523
double newEffectiveMinWidth;
526
if (this.OwningGrid == null)
528
newEffectiveMinWidth = DataGrid.DATAGRID_defaultMinColumnWidth;
532
newEffectiveMinWidth = this.OwningGrid.MinColumnWidth;
537
newEffectiveMinWidth = value;
539
if (this.Width < newEffectiveMinWidth)
541
this.Width = newEffectiveMinWidth;
543
this.LocalMinWidth = value;
553
public Visibility Visibility
557
return this._visibility;
561
if (value != this.Visibility)
563
if (this.OwningGrid != null)
565
this.OwningGrid.OnColumnVisibleStateChanging(this);
567
this._visibility = value;
568
if (this.OwningGrid != null)
570
this.OwningGrid.OnColumnVisibleStateChanged(this);
580
return this.InheritedWidth;
584
double minWidth = this.InheritedMinWidth;
585
if (value < minWidth)
587
// If it's 0, we inherit the width from the DataGrid; We don't need to check
588
// the inherited value here because it's already checked when it's set
591
throw DataGridError.DataGrid.ValueMustBeGreaterThanOrEqualTo("value", "Width", minWidth);
594
if (value > DATAGRIDCOLUMN_maximumWidth)
596
throw DataGridError.DataGrid.ValueMustBeLessThanOrEqualTo("value", "Width", DATAGRIDCOLUMN_maximumWidth);
598
double oldInheritedWidth = this.InheritedWidth;
599
double newInheritedWidth;
602
newInheritedWidth = (this.OwningGrid == null) ? DataGrid.DATAGRID_defaultColumnWidth : this.OwningGrid.ColumnWidth;
606
newInheritedWidth = value;
608
if (oldInheritedWidth != newInheritedWidth)
614
this.LocalWidth = value;
615
if (this.OwningGrid != null)
617
this.OwningGrid.OnColumnWidthChanged(this);
623
#endregion Public Properties
625
#region Internal Properties
627
internal bool DisplayIndexHasChanged
633
internal int DisplayIndexInternal
637
Debug.Assert(value >= -1);
638
Debug.Assert(value < Int32.MaxValue);
640
this._displayIndex = value;
644
internal bool HasHeaderCell
648
return this._headerCell != null;
669
internal DataGridColumnHeader HeaderCell
673
if (this._headerCell == null)
675
this._headerCell = new DataGridColumnHeader();
677
// Take the style set on this column or the one defined at the DataGrid level
678
Style style = this.HeaderStyle;
679
if (style == null && this.OwningGrid != null)
681
style = this.OwningGrid.ColumnHeaderStyle;
685
this._headerCell.Style = style;
688
this._headerCell.OwningColumn = this;
689
this._headerCell.Content = this._header;
691
return this._headerCell;
695
internal double InheritedMinWidth
699
if (this.LocalMinWidth == 0)
701
return (this.OwningGrid == null) ? DataGrid.DATAGRID_defaultMinColumnWidth : this.OwningGrid.MinColumnWidth;
703
return this.LocalMinWidth;
707
internal double InheritedWidth
711
if (this.LocalWidth == 0)
713
return this.OwningGrid == null ? DataGrid.DATAGRID_defaultColumnWidth : this.OwningGrid.ColumnWidth;
715
return this.LocalWidth;
720
internal bool IsFrozen
724
return this._isFrozen;
728
if (value != this.IsFrozen)
730
if (this.OwningGrid != null)
732
this.OwningGrid.OnColumnFrozenStateChanging(this);
734
this._isFrozen = value;
735
if (this.OwningGrid != null)
737
this.OwningGrid.OnColumnFrozenStateChanged(this);
757
internal double LocalMinWidth
763
internal double LocalWidth
769
internal DataGrid OwningGrid
799
#endregion Internal Properties
801
#region Public Methods
803
public FrameworkElement GetElement(DataGridRow dataGridRow)
805
if (dataGridRow == null)
807
throw new ArgumentNullException("dataGridRow");
809
if (this.OwningGrid == null)
811
throw DataGridError.DataGrid.NoOwningGrid(this.GetType());
813
Debug.Assert(this.Index >= 0);
814
Debug.Assert(this.Index < this.OwningGrid.Columns.Count);
815
DataGridCell dataGridCell = dataGridRow.Cells[this.Index];
816
Debug.Assert(dataGridCell != null);
817
return dataGridCell.Content as FrameworkElement;
820
public FrameworkElement GetElement(object dataItem)
822
if (dataItem == null)
824
throw new ArgumentNullException("dataItem");
826
if (this.OwningGrid == null)
828
throw DataGridError.DataGrid.NoOwningGrid(this.GetType());
830
Debug.Assert(this.Index >= 0);
831
Debug.Assert(this.Index < this.OwningGrid.Columns.Count);
832
DataGridRow dataGridRow = this.OwningGrid.GetRowFromItem(dataItem);
833
if (dataGridRow == null)
838
return GetElement(dataGridRow);
842
/// Called by the DataGrid control when a column asked for its
843
/// elements to be updated, typically because one of its properties changed.
845
/// <param name="element">Indicates the element that needs to be updated</param>
846
/// <param name="propertyName">Indicates which property changed and caused this call</param>
847
public virtual void UpdateElement(FrameworkElement element, string propertyName)
851
#endregion Public Methods
853
#region Protected Methods
856
/// Called by a specific column type when one of its properties changed,
857
/// and its current cells need to be updated.
859
/// <param name="propertyName">Indicates which property changed and caused this call</param>
860
protected void UpdateElements(string propertyName)
862
if (this.OwningGrid == null)
866
this.OwningGrid.UpdateColumnElements(this, propertyName);
869
#endregion Protected Methods
871
#region Internal Methods
880
#endregion Internal Methods
882
#region Private Methods
898
#endregion Private Methods