【发布时间】:2010-06-28 15:23:32
【问题描述】:
我想在ListView 中将Dictionary<string, List<int>> 绑定到GridView,但运气不佳。
我看过这个问题:wpf-binding-dictionarystring-liststring-to-listview-listbox-how,还有这个问题:dictionary-binding-to-listview
但我不确定如何获取他们的代码并让它为我工作。
这是我尝试过的:
XAML:
<Window x:Class="WpfIdeas.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="315">
<Grid x:Name="theGrid">
<ListView x:Name="lv">
</ListView>
</Grid>
</Window>
C#:
public partial class Window1 : Window
{
private Dictionary<string, List<int>> lists = new Dictionary<string, List<int>>();
public Window1()
{
InitializeComponent();
lists["a"] = new List<int>(new int[] {1, 2, 3, 4, 5});
lists["b"] = new List<int>(new int[] { 6, 7, 8, 9});
lists["c"] = new List<int>(new int[] { 1, 2, 3, 4, 5 });
GridView gv = new GridView();
foreach(string k in lists.Keys)
{
Binding binding = new Binding("[" + k + "]");
gv.Columns.Add(new GridViewColumn
{
DisplayMemberBinding = binding,
Header = k,
Width = 100
});
}
lv.ItemsSource = lists;
lv.View = gv;
}
}
如何让列表显示在窗口中的相应标题下方?
【问题讨论】:
标签: c# wpf gridview dictionary .net-3.5