共用方式為


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: https://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

  • Anonymous
    October 14, 2008
    As you might have heard , we just released Silverlight 2 , and with it the first version of the Silverlight

  • Anonymous
    October 16, 2008
    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...

  • Anonymous
    October 16, 2008
    Thanks Harlequin, We'll take a look into that. -Scott

  • Anonymous
    October 16, 2008
    In this issue: Tim Heuer, Scott Morrison, Corey Schuman, and Jesse Liberty A whole bunch of folks are

  • Anonymous
    October 16, 2008
    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.

  • Anonymous
    October 16, 2008
    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

  • Anonymous
    October 16, 2008
    The comment has been removed

  • Anonymous
    October 16, 2008
    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 :)

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

  • Anonymous
    October 22, 2008
    Silverlight 2.0 Immersivity: Datagrid Two-Way Data Binding

  • Anonymous
    October 22, 2008
    @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?

  • Anonymous
    October 26, 2008
    The comment has been removed

  • Anonymous
    December 17, 2008
    The comment has been removed