【发布时间】:2014-02-26 03:21:25
【问题描述】:
我的意思是我应该如何显示我的数据结构,因为我可以像使用表格一样使用它? 我希望有一个可以动态添加和删除行和列的表,但其余部分应该看起来像一个表。
现在它像 IList> 一样表示,因为我应该调整它的大小,正如我之前所说的。但现在我想在 DataGrid 中显示它,并且能够拥有行、列和使用“单元格”。但我无法正确绑定它,它不显示任何内容,每行只有一个空单元格。
我该怎么办?或者 mby 使用数组并在每行/列添加后调整它们的大小?
请指教。
现在我有了这个:
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
var storage = new Storage();
storage.Data.Add(new DataRow("Bla-bla")
{
new DataEntity() {Text = "bla-bla", Forces = new[] {ForceEnum.AA}},
new DataEntity() {Text = "bla-bla", Forces = new[] {ForceEnum.UA}}
});
DataListView.DataContext = new StorageModel(storage);
}
public class StorageModel
{
public StorageModel()
{
}
public StorageModel(IStorage storage)
{
DataRowList = new ObservableCollection<DataRow>(storage.Data);
}
public ObservableCollection<DataRow> DataRowList
{
get;
set;
}
}
public class DataRow : IList<DataEntity>
{
public string Name { get; private set; }
private readonly List<DataEntity> _list = new List<DataEntity>();
...
_
<ListView ItemsSource="{Binding DataRowList}" Name="DataListView">
<ListView.ItemTemplate>
<DataTemplate>
<ListView ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我希望能够创建类似于 this 的东西,但具有 2 向绑定...
【问题讨论】:
标签: c# .net wpf data-binding