是否有 ITypedList 的 Silverlight 等效项?
我有一个对象集合,每个对象都包含一组名称/值对。所有对象的名称都是相同的。我想将它们显示为数据网格中的列。
在 Winforms/WPF 中,我将使用 ITypedList
和一些 PropertyDescriptor
实例来向运行时提供一些假属性。然而这种类型在 Silverlight 中似乎不可用。
那么,是否有替代方案,或者 Silverlight 中不存在这种替代方案?
编辑添加一些代码以更好地构建场景
public class Cell {
public string Name { get; private set; }
public string Value { get; private set; }
}
public class Row {
public IEnumerable<Cell> Cells { get; private set; }
}
public class ViewModel {
public IEnumerable<Row> Rows { get; private set; }
}
<sdk:DataGrid ItemsSource="{Binding Rows}" />
如何使行/单元格查找正常工作并填充DataGrid
?具体来说,我希望一旦 Rows
属性发生更改,网格就通过绑定进行更新(假设它引发了绑定响应的更改事件。)
I have a collection of objects, each of which holds a set of name-value pairs. The names are the same across all objects. I'd like to show these as columns in a data grid.
In Winforms/WPF I'd use ITypedList
with some PropertyDescriptor
instances to provide some fake properties to the runtime. However this type does not seem to be available in Silverlight.
So, is there an alternative, or does this not exist in Silverlight?
EDIT adding some code to frame the scenario better
public class Cell {
public string Name { get; private set; }
public string Value { get; private set; }
}
public class Row {
public IEnumerable<Cell> Cells { get; private set; }
}
public class ViewModel {
public IEnumerable<Row> Rows { get; private set; }
}
<sdk:DataGrid ItemsSource="{Binding Rows}" />
How can I get the row/cell lookup to work and populate the DataGrid
? Specifically I want the grid to update via binding once the Rows
property changes (assume it raises a change event that the binding responds to.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,我能够通过使用绑定和字符串索引器解决这个问题。
然后手动构建网格列:
这意味着数据会自动更新,因为在我的例子中,整个
Data
属性被替换,并且实现了INotifyPropertyChanged
来通知绑定。In the end I was able to solve this issue by using bindings and a string indexer.
Then build the grid columns manually:
This meant that the data updated automatically, because in my case the entire
Data
property was replaced, andINotifyPropertyChanged
implemented to notify the binding.