As mentioned we made some changes, hopefully for the better, to the DataGrid API since Beta 2. Special thanks to our developer Yifung Lin for compiling this list:
Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.
DisplayMemberBinding wasn’t an ideal name, but we used it because WPF has some precedence with it. This breaks down in scenarios where there is a separate Binding for display like in ComboBox scenarios since our Binding is actually the property field binding as opposed to the display binding.
Users using DataGridBoundColumn will need to change DisplayMemberBinding to Binding.
Beta 2
[Xaml]
<data:DataGridTextColumn DisplayMemberBinding="{Binding FirstName}" />
RTM
<data:DataGridTextColumn Binding="{Binding FirstName}" />
The DataGrid now supports the Visual State Manager.
Custom DataGrid templates need to be updated. The new templates can be found at: http://msdn.microsoft.com/library/cc278066(vs.95).aspx
In the full framework IEditableObject is part of the System.ComponentModel namespace and it is located in System.dll For Silverlight, it was temporarily in the System.Windows.Controls.Data.dll under the System.Windows.Controls namespace. It now matches the full framework.
Users using IEditableObject need to update the namespace.
[c#]
using System.Windows.Controls;
using System.ComponentModel;
Using SelectionChangedEventHandler allows the user to access OldItems and NewItems.
The signature for the SelectionChanged event handler needs to be updated.
void SelectionChanged(object sender, EventArgs e) { }
void SelectionChanged(object sender, SelectionChangedEventArgs e) { }
DataGridHeadersVisibility is a better indication of what the enum is.
DataGridHeaders -> DataGridHeadersVisibility.
dataGrid.HeadersVisibility = DataGridHeaders.Column;
dataGrid.HeadersVisibility = DataGridHeadersVisibility.Column;
The PropertyInfo of DataGridAutoGeneratingColumnEventArgs was changed to PropertyName and PropertyType.
Update to use PropertyName and PropertyType.
string name = e.Property.Name; Type type = e.Property.Type;
string name = e.PropertyName; Type type = e.PropertyType;
GenerateElement and GenerateEditingElement now provide the containing cell
Update signature.
protected override FrameworkElement GenerateEditingElement(object dataItem) { } protected override FrameworkElement GenerateElement(object dataItem) { }
protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) { } protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem) { }
The following modifications were made to the DataGridColumnReorderingEventArgs:
Old:
public object DragIndicatorContent { get; set} public FrameworkElement DropLocationIndicator { get; set}
New:
public Control DragIndicator { get; set} public Control DropLocationIndicator { get; set}
Update to use DragIndicator.
object dragIndicator = e.DragIndicatorContent; FrameworkElement dropIndicator = e.DropLocationIndicator;
Control dragIndicator = e.DragIndicator; Control type = e.DropLocationIndicator;
Explicit Binding is required to implement these 2 events correctly. Since the Silverlight Binding does not support explicit Bindings, these events were removed. They will be resurrected when explicit Binding is supported.
The DataGrid.CancelingEdit and the DataGrid.CommittingEdit events can no longer be used. It is recommended that you use IEditableObject to track when a commit has occurred.
The concept of a DataError event was taken from Winforms. This does not fit well into the WPF model so the event was removed.
The DataGrid.DataError event can no longer be used.
Visuals cannot be duplicated so they cannot be used for the Header property due to column reordering.
To put visuals in column headers, users will need to use the header's ContentTemplate to include the visual instead of setting it as the Header.
<data:DataGridTextColumn DisplayMemberBinding="{Binding FirstName}"> <data:DataGridTextColumn.Header> <Button Content="hello" /> </data:DataGridTextColumn.Header> </data:DataGridTextColumn>
<data:DataGridTextColumn Binding="{Binding LastName}" Header="hello"> <data:DataGridTextColumn.HeaderStyle> <Style TargetType="dataprimitives:DataGridColumnHeader"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <Button Content="{Binding}" /> </DataTemplate> </Setter.Value> </Setter> </Style> </data:DataGridTextColumn.HeaderStyle> </data:DataGridTextColumn>
DataGridFrozenGrid derives from Grid and it contains an IsFrozen attached property. Users can use IsFrozen to specify parts of the Row that are frozen
Custom DataGridRow templates need to use DataGridFrozenGrid as the root element instead of Grid.
Gridline would be appropriate if it was a word. MS Word says it is, but the dictionary says it’s not. WPF has precedence with GridLine so we went with that.
All instances of Gridline need to be renamed to GridLine.
dataGrid.GridlinesVisibility = DataGridGridlinesVisibility.All;
dataGrid.GridLinesVisibility = DataGridGridLinesVisibility.All;
These types moved from the System.Windows.Controls namespace to the System.Windows.Controls.Primitives namespace:
The types above need to be referenced using the System.Windows.Controls.Primitives namespace.
The Content property was not useful for mainline scenarios so it was removed.
The DataGridCheckBoxColumn.Content property can no longer be used. In rare scenarios where it is needed, users can template the CheckBox through ElementStyle and EditingElementStyle