none
为什么我在SilverLight4中向DataGrid绑定数据时提示Binding为null RRS feed

  • 问题

  • xaml:

    <sdk:DataGrid AutoGenerateColumns="True" Height="291" Margin="12,50,12,0" Name="dgMatches" VerticalAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ItemsSource="{Binding}">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="赛事编号" IsReadOnly="True" Width="Auto" Binding="{Binding MatchNumber}" />
                </sdk:DataGrid.Columns>
            </sdk:DataGrid>

    后台:

    void _Client_GetOddsCompleted(object sender, GetOddsCompletedEventArgs e)
            {
                dgMatches.ItemsSource = e.Result;
            }

    错误提示:

    "System.ArgumentNullException: 值不能为 null。
    参数名: binding  
    位于 System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)\r\n   位于 System.Windows.FrameworkElement.SetBinding(DependencyProperty dp, Binding binding)\r\n   位于 System.Windows.Controls.DataGridTextColumn.GenerateElement(DataGridCell cell, Object dataItem)\r\n   位于 System.Windows.Controls.DataGridColumn.GenerateElementInternal(DataGridCell cell, Object dataItem)\r\n   位于 System.Windows.Controls.DataGrid.PopulateCellContent(Boolean isCellEdited, DataGridColumn dataGridColumn, DataGridRow dataGridRow, DataGridCell dataGridCell)\r\n   位于 System.Windows.Controls.DataGrid.AddNewCellPrivate(DataGridRow row, DataGridColumn column)\r\n   位于 System.Windows.Controls.DataGrid.CompleteCellsCollection(DataGridRow dataGridRow)\r\n   位于 System.Windows.Controls.DataGrid.GenerateRow(Int32 rowIndex, Int32 slot, Object dataContext)\r\n   位于 System.Windows.Controls.DataGrid.GenerateRow(Int32 rowIndex, Int32 slot)\r\n   位于 System.Windows.Controls.DataGrid.AddSlots(Int32 totalSlots)\r\n   位于 System.Windows.Controls.DataGrid.RefreshRows(Boolean recycleRows, Boolean clearRows)\r\n   位于 System.Windows.Controls.DataGrid.RefreshRowsAndColumns(Boolean clearRows)\r\n   位于 System.Windows.Controls.DataGrid.MeasureOverride(Size availableSize)\r\n   位于 System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)"

    2012年9月5日 9:36

答案

全部回复