在列表视图中显示动态数据,gridview
问题描述:
我从API中收集dictionary <string, string>
。在列表视图中显示动态数据,gridview
我在网格视图名称和值,以显示我的WPF的形式对这个数据作为两列
<ListView Name="LstCustomProperties" ItemsSource="{Binding CustomPropertyTable}">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Key}" />
<GridViewColumn Header="Value" DisplayMemberBinding="{Binding Value}" />
</GridView>
</ListView.View>
</ListView>
我也有形式上的两个按钮来添加按钮添加新的项目或删除删除任何项目。当用户单击确定时,字典将根据当前名称,值列表中的值对进行更新。我没有得到如何添加和修改列表视图中的当前数据或使用任何其他控件。
答
我宁愿在这里使用ObservableCollection
。所以当你收集任何物品时,UI会自动刷新。
请看下面的例子:
public class CustomDictionary
{
public string Key { get; set; }
public string Value { get; set; }
public CustomDictionary(string key, string value)
{
this.Key = key;
this.Value = value;
}
}
public class CustomDictionaryCollection : ObservableCollection<CustomDictionary>
{
}
public class MyData
{
public CustomDictionaryCollection CustomPropertyTable { get; set; }
public MyData()
{
this.CustomPropertyTable.Add(new CustomDictionary("myKey", "myValue"));
}
}
现在当你在CustomPropertyTable
添加任何东西,在ListView
将自动得到更新。
希望这有助于
我不想在对象直接添加它会在电网和当其用户点击将被保存到对象和API将更新的数据存储。 – Mohit 2010-11-19 08:28:57
抱歉,因为我在度假时太晚了。 我还想让用户从列表视图中编辑值成员,我们将非常感谢这方面的任何帮助 – Mohit 2010-11-30 12:21:40