【问题标题】:Silverlight datagrid does not bindingSilverlight 数据网格不绑定
【发布时间】:2012-01-20 10:11:45
【问题描述】:

嘿,我有按钮:

 GetData();
            dataGrid1.ItemsSource = DriverCollection.ToList();

当我点击它时,datagrid 不会只添加两行(我的集合包含两行),它是空的且非常窄

这是我的课

 private class DriverData 
        {
            public string DriverName { get; set; }
            public decimal DriverSalary { get; set; }
        }

收藏:

private ObservableCollection<DriverData> _DriverCollection = new ObservableCollection<DriverData>();

private ObservableCollection<DriverData> DriverCollection 
        {
            get { return _DriverCollection; }
        }

GetData 方法

for (int i = 0; i < FilteredDriverNamesList.Count; i++)
            {
                _DriverCollection.Add(new DriverData { DriverName = FilteredDriverNamesList[i], DriverSalary = _DriverSalarys[i] });
            }

和网格:

 <sdk:DataGrid AutoGenerateColumns="False" Name="dataGrid1" FontSize="14" Margin="12,0,0,0"
                      HorizontalAlignment="Left" Width="549" Height="273" VerticalAlignment="Top" ItemsSource="{Binding DriverCollection}">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Binding="{Binding DriverName}" Width="200"/>
                <sdk:DataGridTextColumn Binding="{Binding DriverSalary}" Width="140"/>
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>

编辑:我已经解决了我在课堂上私下编辑的问题 谢谢

【问题讨论】:

    标签: silverlight-4.0 datagrid observablecollection


    【解决方案1】:

    好的,到目前为止,你做得很好,

    您能否更改 DriverCollection 并将其公开。即

     public ObservableCollection<DriverData> DriverCollection 
        {
            get { return _DriverCollection; }
        }
    

    【讨论】:

      猜你喜欢
      • 2011-10-29
      • 2014-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-11
      • 1970-01-01
      相关资源
      最近更新 更多