Silverlight数据网格不绑定

发布于 2024-12-21 08:19:43 字数 1543 浏览 2 评论 0原文

嘿,我有按钮:

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

当我单击它时,数据网格不会填充,仅添加两行(我的集合包含两行),这是空的且非常窄,

这是我的类

 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>

编辑:我已经解决了我在班级上用公共编辑的问题 谢谢

Hey gus i have button:

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

When i click it datagrid does not filling only adding two rows (my collection contains two rows) which is empty and very narrow

this is my class

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

collection :

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

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

GetData method << its works correctly collection is filling with two rows:

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

and the grid:

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

Edit: I have solved the problem i edited private with public on my class
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏月而来 2024-12-28 08:19:43

好的,到目前为止您所做的工作非常出色,

您可以更改 DriverCollection 并将其公开吗? IE

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

Ok, this is great job you have done so far,

Can you change DriverCollection and make it public. i.e

 public ObservableCollection<DriverData> DriverCollection 
    {
        get { return _DriverCollection; }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文