Post Beta 2 Breaking Changes


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:

DataGrid breaking changes

DisplayMemberBinding renamed to Binding

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

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.

Fix Required

Users using DataGridBoundColumn will need to change DisplayMemberBinding to Binding.

Beta 2

[Xaml]

<data:DataGridTextColumn DisplayMemberBinding="{Binding FirstName}" />

RTM

[Xaml]

<data:DataGridTextColumn Binding="{Binding FirstName}" />

 

DataGrid has VSM support

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

The DataGrid now supports the Visual State Manager.

Fix Required

Custom DataGrid templates need to be updated.  The new templates can be found at: http://msdn.microsoft.com/library/cc278066(vs.95).aspx

 

IEditableObject moved to System.ComponentModel namespace

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

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.

Fix Required

Users using IEditableObject need to update the namespace.

Beta 2

[c#]

using System.Windows.Controls;

RTM

[c#]

using System.ComponentModel;

 

SelectionChanged event changed from EventHandler to SelectionChangedEventHandler

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

Using SelectionChangedEventHandler allows the user to access OldItems and NewItems.

Fix Required

The signature for the SelectionChanged event handler needs to be updated.

Beta 2

[c#]

void SelectionChanged(object sender, EventArgs e)
{

}

RTM

[c#]

void SelectionChanged(object sender, SelectionChangedEventArgs e)
{

}

 

DataGridHeaders enum renamed to DataGridHeadersVisibility

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

DataGridHeadersVisibility is a better indication of what the enum is.

Fix Required

DataGridHeaders -> DataGridHeadersVisibility.

Beta 2

[c#]

dataGrid.HeadersVisibility = DataGridHeaders.Column;

RTM

[c#]

dataGrid.HeadersVisibility = DataGridHeadersVisibility.Column;

 

DataGridAutoGeneratingColumnEventArgs change

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

The PropertyInfo of DataGridAutoGeneratingColumnEventArgs was changed to PropertyName and PropertyType.

Fix Required

Update to use PropertyName and PropertyType.

Beta 2

[c#]

string name = e.Property.Name;
Type type = e.Property.Type;

RTM

[c#]

string name = e.PropertyName;
Type type = e.PropertyType;

 

DataGridColumn GenerateElement and GenerateEditingElement now take in the cell

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

GenerateElement and GenerateEditingElement now provide the containing cell

Fix Required

Update signature.

Beta 2

[c#]

protected override FrameworkElement GenerateEditingElement(object dataItem)
{

}

protected override FrameworkElement GenerateElement(object dataItem)
{ 

}

RTM

[c#]

protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)
{

}

protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
{ 

}

 

DataGridColumnReorderingEventArgs changed

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

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}

Fix Required

Update to use DragIndicator.

Beta 2

[c#]

object dragIndicator = e.DragIndicatorContent;
FrameworkElement dropIndicator = e.DropLocationIndicator;

RTM

[c#]

Control dragIndicator = e.DragIndicator;
Control type = e.DropLocationIndicator;

 

DataGrid.CancelingEdit and DataGrid.CommittingEdit events removed

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

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.

Fix Required

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.

 

DataGrid.DataError event removed

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

The concept of a DataError event was taken from Winforms.  This does not fit well into the WPF model so the event was removed.

Fix Required

The DataGrid.DataError event can no longer be used.

 

DataGridColumn.Header no longer supports visuals

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

Visuals cannot be duplicated so they cannot be used for the Header property due to column reordering.

Fix Required

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.

Beta 2

[Xaml]

<data:DataGridTextColumn DisplayMemberBinding="{Binding FirstName}">
    <data:DataGridTextColumn.Header>
        <Button Content="hello" />
    </data:DataGridTextColumn.Header>
</data:DataGridTextColumn>

RTM

[Xaml]

<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>

 

Root element of DataGridRow changed from Grid to DataGridFrozenGrid

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

DataGridFrozenGrid derives from Grid and it contains an IsFrozen attached property.  Users can use IsFrozen to specify parts of the Row that are frozen

Fix Required

Custom DataGridRow templates need to use DataGridFrozenGrid as the root element instead of Grid.

 

Gridline renamed to GridLine

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

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.

Fix Required

All instances of Gridline need to be renamed to GridLine.

Beta 2

[c#]

dataGrid.GridlinesVisibility = DataGridGridlinesVisibility.All;

RTM

[c#]

dataGrid.GridLinesVisibility = DataGridGridLinesVisibility.All;

 

Template only controls moved to primitives namespace

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

These types moved from the System.Windows.Controls namespace to the System.Windows.Controls.Primitives namespace:

  • DataGridCellsPresenter
  • DataGridColumnHeadersPresenter
  • DataGridDetailsPresenter
  • DataGridRowsPresenter
  • DataGridColumnHeader
  • DataGridRowHeader
Fix Required

The types above need to be referenced using the System.Windows.Controls.Primitives namespace.

 

DataGridCheckBoxColumn.Content was removed

Who Is Affected: Silverlight 2 Beta 2 managed applications that use the DataGrid.

Summary

The Content property was not useful for mainline scenarios so it was removed.

Fix Required

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

Comments (13)

  1. As you might have heard , we just released Silverlight 2 , and with it the first version of the Silverlight

  2. Harlequin says:

    Looks like when you use <data:DataGridTextColumn.HeaderStyle> you can’t use the vsm: inside of it. Wonder if that’s a bug or not. Doesn’t seem to activate the appropriate VisualStates…

  3. Thanks Harlequin,

    We’ll take a look into that.

    -Scott

  4. In this issue: Tim Heuer, Scott Morrison, Corey Schuman, and Jesse Liberty A whole bunch of folks are

  5. Harlequin says:

    Another fun one 🙂

    <my:DataGridTemplateColumn.Header>

      <HyperlinkButton Content="Stage"  Style="{StaticResource WhiteHyperlinkButtonStyle}" Tag="Stage" Click="Sort_Click" />

    </my:DataGridTemplateColumn.Header>

    If you have code like this(which worked in Beta 2), how would you do this in the new DataGrid then? Since you can’t have Click events inside the HeaderStyle.

    Noting that we currently have custom paging, so the built in datagrid only sorts the current listing for us, not the full grid.

  6. Hi Harlequin,

    To replace:

    <my:DataGridTemplateColumn.Header>

     <HyperlinkButton Content="Stage"  Style="{StaticResource WhiteHyperlinkButtonStyle}" Tag="Stage" Click="Sort_Click" />

    </my:DataGridTemplateColumn.Header>

    You would use:

    <data:DataGrid.ColumnHeaderStyle>

      <Style TargetType="dataPrim:DataGridColumnHeader">

         <Setter Property="ContentTemplate">

            <Setter.Value>

               <DataTemplate>

                  <HyperlinkButton Content="Stage" Tag="Stage" Style="{StaticResource WhiteHyperlinkButtonStyle}" Click="HyperlinkButton_Click" />

               </DataTemplate>

            </Setter.Value>

         </Setter>

      </Style>

    </data:DataGrid.ColumnHeaderStyle>

    In the code aboce, the Click event will get fired.  Also, if you have your tempaltes locally scoped in the UserControl, events should work properly.  The issue that you are probably seeing is App-level resources not being able to contain event hookups that work.

    Hope this helps.

    Scott

  7. Harlequin says:

    Gotcha.

    Kind of puzzled as to this implentation though. Since you’re pretty much forced to override the entire ColumnHeaderStyle for the column if you want to put something special inside. No?

    Means if you already have a complex ColumnHeaderStyle for your DataGrid, you need to override the whole shebang-a-ding-dong for EVERY column. Kinda seems why we had the .Header in the first place, so you could shove in a control.

    Unless there’s a workaround I haven’t found yet.

  8. Harlequin says:

    And one last thing to fix then I’m done converting this big project over…:)

    …how do you add TextWrapping to the hyperlink template, or the Hyperlink itself? There’s 3 textblocks in the base template, NormalTextBlock, UnderlineTextBlock and DisabledOverlay. And adding TextWrapping to them does nothing to the hyperlink itself. Even adding a Width to the Hyperlink just clips it, and doesn’t force it onto 2 lines.

    p.s. This is a HUGE internal MS project we’re trying to clean up, thus all the messages 🙂

  9. miguel says:

    setting DataGridCell.Background does not work.  There are no errors, but nothing happens.  How should the background to the cell be changed at runtime?

  10. Dave Burke says:

    Silverlight 2.0 Immersivity: Datagrid Two-Way Data Binding

  11. John "Z-Bo" Zabroski says:

    @Visuals cannot be duplicated so they cannot be used for the Header property due to column reordering.

    I don’t understand this?  Do you mean objects that have Layout?  It seems like an artificial reason…that will be fixed in the future?

  12. brauliod says:

    Another breaking change… (it’s more a bug), dropdown boxes as they are does not behave well in DataGrid (there is a workaround in a blog to disaply properly the box).

  13. Frank says:

    Thanks!!!! I really appreciae your help .. am tring to upgrade a flash application I did not write but paid for to a silverlight app .. the Microsoft blogs, videos, and Jesse’s print tutorials are a lifesaver .