This topic discusses the changes made to the Silverlight DataGrid control between the Microsoft Silverlight 2 Beta 1 and the Beta 2 releases. The changes discussed in this article are focused on changes that might cause your older Silverlight-based applications to now fail or behave differently, not on new features/enhancements for this release.
For more information, see Breaking Changes Between Beta 1 and Beta 2.
AutoGenerateColumns behavior modified
Who Is Affected: Silverlight 2 Beta 1 managed applications that use the DataGrid.
Summary
The behavior for auto column generation was drastically modified. See the differences below.
Fix Required
Users using the DataGrid may or may not need to modify their code to turn dataGrid.AutoGenerateColumns on or off. Additionally, users depending on columns to be autogenerated instantaneously may need to change their code to wait for the Loaded event or use the AutogeneratingColumn event.
Beta 1
Beta 2
dataGrid.ItemsSource = myList;
dataGrid.AutoGenerateColumns = false;
DependencyProperty DataGrid.SelectedItemsProperty removed
Who Is Affected: Silverlight 2 managed applications that use the DataGrid.SelectedItemsProperty dependency property.
The SelectedItems can be modified the collection’s methods, but the property itself is a readonly property. In Beta1, the property was backed by a DependencyProperty that threw an InvalidOperationException when it was set. The motivation for doing so came from the WPF ListBox, but in talking to WPF we decided that what the ListBox does is wrong. Instead of a DependencyProperty, it is now a readonly CLR property
SelectedItems can no longer be used as a DependencyProperty
PreparingRow/CleaningRow renamed to LoadingRow/UnloadingRow
Who Is Affected: Silverlight 2 Beta 1 managed applications listening to dataGrid.PreparingRow or dataGrid.CleaningRow.
The PreparingRow and the CleaningRow events have been renamed to LoadingRow and UnloadingRow. In addition, CleaningRow event is no longer cancelable.
Use LoadingRow and UnloadingRow instead of PreparingRow and CleaningRow.
[C#]
dataGrid.PreparingRow += new EventHandler<DataGridRowEventArgs>(dataGrid_PreparingRow);
dataGrid.CleaningRow += new EventHandler<DataGridRowCancelEventArgs>(dataGrid_CleaningRow);
dataGrid.LoadingRow += new EventHandler<DataGridRowEventArgs>(dataGrid_LoadingRow);
dataGrid.UnloadingRow += new EventHandler<DataGridRowEventArgs>(dataGrid_UnloadingRow);
DataGridColumnBase renamed to DataGridColumn
Who Is Affected: Silverlight 2 Beta 1 managed applications using the DataGridColumnBase type explicitly.
DataGridColumnBase was renamed to DataGridColumn.
Any explicit uses of DataGridColumnBase require a name change to DataGridColumn.
DataGridColumnBase column = dataGrid.Columns[0];
DataGridColumn column = dataGrid.Columns[0];
DataGridBoundColumnBase renamed to DataGridBoundColumn
Who Is Affected: Silverlight 2 Beta 1 managed applications using the DataGridBoundColumnBase type explicitly.
DataGridBoundColumnBase was renamed to DataGridBoundColumn.
Any explicit uses of DataGridBoundColumnBase require a name change to DataGridBoundColumn.
DataGridBoundColumnBase boundColumn = dataGrid.Columns[0] as DataGridBoundColumnBase;
DataGridBoundColumn boundColumn = dataGrid.Columns[0] as DataGridBoundColumn;
DataGridTextBoxColumn renamed to DataGridTextColumn
Who Is Affected: Silverlight 2 Beta 1 managed applications using the DataGridTextBoxColumn type explicitly.
DataGridTextBoxColumn was renamed to DataGridTextColumn.
Any explicit uses of DataGridTextBoxColumn require a name change to DataGridTextColumn.
((DataGridTextBoxColumn)dataGrid.Columns[0]).FontSize = 11;
((DataGridTextColumn)dataGrid.Columns[0]).FontSize = 11;
HeaderTemplate property removed
Who Is Affected: Silverlight 2 Beta 1 managed applications using the dataGrid.HeaderTemplate property.
The HeaderTemplate property which could be applied to RowHeaders or ColumnHeaders was removed.
Users previously using HeaderTemplate for RowHeaders or ColumnHeaders will use dataGrid.RowHeaderStyle to set the template for RowHeaders or dataGrid.ColumnHeaderStyle to set the template for ColumnHeaders. Alternatively, users could set the style or template on individual RowHeaders or ColumnHeaders explicitly.
RowDetailsVisibility renamed to RowDetailsVisibilityMode
Who Is Affected: Silverlight 2 Beta 1 managed applications using the dataGrid.RowDetailsVisibility enumeration.
RowDetailsVisibility was renamed to RowDetailsVisibilityMode to better reflect what it is and not imply that it is of type Visibility.
Any use of RowDetailsVisibility requires a name change to RowDetailsVisibilityMode.
dataGrid.RowDetailsVisibility = RowDetailsVisibility.VisibleWhenSelected;
dataGrid.RowDetailsVisibilityMode = RowDetailsVisibilityMode.VisibleWhenSelected;
CheckBoxContentBinding changed to Content
Who Is Affected: Silverlight 2 Beta 1 managed applications using dataGridCheckBoxColumn.CheckBoxContentBinding.
There is no need for a Binding in this case so we’ve changed this to an object named Content that maps to the Content property of the CheckBoxes within the column
Users using CheckBoxContentBinding need to change the Binding to the content itself.
dataGridCheckBoxColumn.CheckBoxContentBinding = new Binding(“checkBoxContent”);
dataGridCheckBoxColumn.Content = checkBoxContent;
GetElement renamed to GetCellContent
Who Is Affected: Silverlight 2 Beta 1 managed applications using DataGridColumnBase.GetCellContent.
The GetElement method on DataGridColumn that retrieves content from the cell of a given DataGridRow or DataItem renamed to GetCellContent.
User calling GetElement need to change their calls to GetCellContent.
dataGrid.Columns[0].GetElement(myItems[0]);
dataGrid.Columns[0].GetCellContent(myItems[0]);
UpdateElement renamed to RefreshCellContent
Who Is Affected: Silverlight 2 Beta 1 managed applications using the DataGrid with custom or template columns
The UpdateElement method on DataGridColumnBase was renamed to RefreshCellContent.
Users override UpdateElement in their columns need to override RefreshCellContent instead
public MyColumn : DataGridBoundColumnBase
{
public override void UpdateElement(Frameworkelement element, string propertyName) {…}
}
public MyColumn : DataGridBoundColumn
public override void RefreshCellContent(Frameworkelement element, string propertyName) {…}
UpdateElements renamed to NotifyPropertyChanged
Who Is Affected: Silverlight 2 Beta 1 managed applications using the DataGrid with their own custom columns
The UpdateElements method on DataGridBoundColumnBase was renamed to NotifyPropertyChanged.
Users using the UpdateElements method within a custom column need to now use NotifyPropertyChanged.
public double FontSize
get {…}
set
this._fontSize = value;
UpdateElements(“FontSize”);
NotifyPropertyChanged(“FontSize”);
dataItem parameter added to GenerateElement and GenerateEditingElement
Who Is Affected: Silverlight 2 Beta 1 managed applications using the DataGrid with custom bound columns
The GenerateElement and GenerateEditingElement methods on DataGridBoundColumnBase now take in the dataItem that the row containg the element is bound to.
Users overriding GenerateElement and/or GenerateEditingElement in their custom bound columns need to add the dataItem parameter
public override void GenerateElement() {…}
public override void GenerateEditingElement() {…}
public override void GenerateElement(object dataItem) {…}
public override void GenerateEditingElement(object dataItem) {…}
Index on DataGridBoundColumnBase made internal
Who Is Affected: Silverlight 2 Beta 1 managed applications using the dataGridColumnBase.Index property.
There is no need to have both Index and DisplayIndex exposed for DataGridColumns. Index is an implementation detail so it was made internal.
Users can no longer use the Index property for DataGridColumns. They should use DisplayIndex to reorder columns and access the DisplayMemberBinding if they want to know which field in the DataItem the column is bound to.
dataGrid.GetRowDetailsVisibility changed to DataGridRow.GetRowContainingElement
Who Is Affected: Silverlight 2 Beta 1 managed applications using the GetRowDetailsVisibility method on the DataGrid.
Instead of a method on the DataGrid that returns the visibility of the row details of a row given an element inside the row, we created a more flexible method that returns the row given an element inside the row. Users can then check the row’s DetailsVisibility property for this particular scenario.
Users using dataGrid.GetRowDetailsVisibility need to update the call as follows.
Visibility detailsVisibility = dataGrid.GetRowDetailsVisibility(clickedButton);
DataGridRow clickedRow = DataGridRow.GetRowContainingElement(clickedButton);
Visibility detailsVisibility = clickedRow.DetailsVisibility;
Column Width changed from double to DataGridLength
Who Is Affected: Silverlight 2 Beta 1 managed applications setting dataGridColumnBase.Width outside of xaml.
To support various sizing options for column widths, dataGridColumnBase.Width changed from being being a double to a DataGridLength.
Users using setting dataGridColumnBase.Width outside of xaml will need to instantiate a DataGridLength or use one of the static DataGridLengths (DataGridLength.Auto, DataGridLength.SizeToHeader, DataGridLength.SizeToCells) instead of setting it to a double.
dataGrid.Columns[0].Width = 20;
[Xaml]
<DataGridTextBoxColumn Width=”20” DisplayMemeberBinding=”{Binding foo}” />
dataGrid.Columns[0].Width = new DataGridLength(20);
dataGrid.Columns[0].Width = DataGridLength.Auto;
dataGrid.Columns[0].Width = DataGridLength.SizeToHeader;
dataGrid.Columns[0].Width = DataGridLength.SizeToCells;
<DataGridTextColumn Width=”20” DisplayMemeberBinding=”{Binding foo}” />
<DataGridTextColumn Width=”Auto” DisplayMemeberBinding=”{Binding bar}” />
<DataGridTextColumn Width=”SizeToHeader” DisplayMemeberBinding=”{Binding hello}” />
<DataGridTextColumn Width=”SizeToCells” DisplayMemeberBinding=”{Binding hello}” />
OverrideRowDetailsScrolling renamed to AreRowDetailsFrozen
Who Is Affected: Silverlight 2 Beta 1 managed applications using dataGrid.OverrideRowDetailsScrolling.
The OverrideRowDetailsScrolling property on the DataGrid was renamed to AreRowDetailsFrozen.
Users using OverrideRowDetailsScrolling will need to change the name to AreRowDetailsFrozen.
dataGrid.OverrideRowDetailsScrolling = true;
dataGrid.AreRowDetailsFrozen = true;
ColumnHeadersHeight renamed to ColumnHeaderHeight
Who Is Affected: Silverlight 2 Beta 1 managed applications using dataGrid.ColumnHeadersHeight.
The ColumnHeadersHeight property on the DataGrid was renamed to ColumnHeaderHeight.
Users using ColumnHeadersHeight will need to change the name to ColumnHeaderHeight.
dataGrid.ColumnHeadersHeight = 25;
dataGrid.ColumnHeaderHeight = 25;
RowHeadersWidth renamed to RowHeaderWidth
Who Is Affected: Silverlight 2 Beta 1 managed applications using dataGrid.RowHeadersWidth.
The RowHeadersWidth property on the DataGrid was renamed to RowHeaderWidth.
Users using RowHeadersWidth will need to change the name to RowHeaderWidth.
dataGrid.RowHeadersWidth = 30;
dataGrid.RowHeaderWidth = 30;
Editing API changes
Who Is Affected: Silverlight 2 Beta 1 managed applications using the DataGrid and hooking in to the Editing interface
The editing interface went through drastic changes see the summary below.
Users using the DataGrid and hooking into the editing interface need to update their code base on the new editing API.
The following DataGrid Beta1 editing API has been replaced with the Beta2 API below
public class DataGrid : Control
// Events
public event EventHandler<DataGridCellEditingCancelEventArgs> BeginningCellEdit;
public event EventHandler<DataGridCellEventArgs> CommitCellEdit;
public event EventHandler<DataGridCellCancelEventArgs> CommittingCellEdit;
public event EventHandler<DataGridRowCancelEventArgs> CommittingRowEdit;
protected virtual void OnBeginningCellEdit(DataGridCellEditingCancelEventArgs e);
protected virtual void OnCommitCellEdit(DataGridCellEventArgs e);
protected virtual void OnCommittingCellEdit(DataGridCellCancelEventArgs e);
protected virtual void OnCommittingRowEdit(DataGridRowCancelEventArgs e);
The new Beta2 API for editing is as follows:
public event EventHandler<DataGridBeginningEditEventArgs> BeginningEdit;
public event EventHandler<DataGridEndingEditEventArgs> CancelingEdit;
public event EventHandler<DataGridEndingEditEventArgs> CommittingEdit;
protected virtual void OnBeginningEdit(DataGridEditingEventArgs e);
protected virtual void OnCommittingEdit(DataGridEndingEditEventArgs e);
protected virtual void OnCancelingEdit(DataGridEndingEditEventArgs e);
public enum DataGridEditingUnit
Cell,
Row
Template changes for DataGrid classes
Who Is Affected: Silverlight 2 Beta 1 managed applications that re-template the DataGrid and/or related components
The default templates for the DataGrid and its related classes have changed since Beta1 to Beta2.
Users re-templating the DataGrid will need to re-base their templates using the new Beta 2 templates. The new templates will be available in the Beta 2 update of the DataGrid Styles and Templates topic.