Silverlight数据网格重新绑定整个列
我想将数据网格行索引添加到我的 Silverlight MVVM 应用程序中,因此我创建了一个 IValueConverter,它将获取行对象并返回其索引。转换器本身工作正常,这是简单的行 XAML。
<sdk:DataGridTextColumn Binding="{Binding Converter={StaticResource RowIndexConverter}}" />
问题是当我添加新行时,我必须将其插入到顶部。这会在索引 0 处创建一个新行,并将所有其他行向下推一位,并且它们的行号不会更新。有没有办法强制它重新绑定整个列?
I wanted to add datagrid row indexes to my Silverlight MVVM application so I created an IValueConverter that will take the row object and return it's index. The converter itself is working properly and here's the simple row XAML.
<sdk:DataGridTextColumn Binding="{Binding Converter={StaticResource RowIndexConverter}}" />
The problem is when I add a new row I have to insert it at the top. This creates a new row at index 0 and pushes all of the other rows down one and their row numbers are not updating. Is there a way I can force it to rebind that entire column?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了解决这个问题,您可能应该将 RowIndex 添加到绑定到 DataGrid 的模型中。每当添加/删除行时,更新每个模型项的索引 - 然后您的 DataGrid 将被更新。
To solve this you should probably add RowIndex to the model which you bind to the DataGrid. Whenever rows are added / removed, update the index for each model item - your DataGrid will then be updated.
分离然后重新附加 datagrid.itemssource。
Detach and then reattach the datagrid.itemssource.