C# 如何在DataGrid WPF中显示SortedDictionary?

C# 如何在DataGrid WPF中显示SortedDictionary?,c#,wpf,datagrid,sorteddictionary,C#,Wpf,Datagrid,Sorteddictionary,我想在数据网格中显示一个sortedDictionary,当键为int且值为类类型的列表时,例如值列表的人员 例如: public MainWindow() { InitializeComponent(); SortedDictionary<int, List<Person>> Sd1 = new SortedDictionary<int,List<Person>>(); Person p1

我想在
数据网格
中显示一个
sortedDictionary
,当键为int且值为
类类型的列表
时,例如
值列表
人员

例如:

public MainWindow()
    {
        InitializeComponent();
        SortedDictionary<int, List<Person>> Sd1 = new SortedDictionary<int,List<Person>>();
        Person p1 = new Person("htryh");
        Person p2 = new Person("juyik");
        List<Person> PL = new List<Person>();
        PL.Add(p1);
        PL.Add(p2);
        Sd1.Add(1, PL);
        dt1.ItemsSource = Sd1;

    }
}
class Person
{
    public string Name { get; set; }
    public Person(string name)
    {
        Name = name;
    }
}
public主窗口()
{
初始化组件();
SortedDictionary Sd1=新的SortedDictionary();
人员p1=新人员(“htryh”);
人员p2=新人员(“juyik”);
List PL=新列表();
PL.Add(p1);
PL.Add(p2);
Sd1.添加(1,PL);
dt1.ItemsSource=Sd1;
}
}
班主任
{
公共字符串名称{get;set;}
公众人物(字符串名称)
{
名称=名称;
}
}
在“
Key
”列中的
dataGrid
中,我看到了int,但在“
value
列中,我看到了: (收集)。 我该如何解决这个问题??
谢谢。

在dataGrid上将
自动生成列设置为
False
,并提供您自己的列集

<DataGrid x:Name="dt1" AutoGenerateColumns="False" IsReadOnly="True">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Key" Binding="{Binding Key}"/>
        <DataGridTemplateColumn Header="Value">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <ComboBox ItemsSource="{Binding Value}"
                                IsSynchronizedWithCurrentItem="True"
                                DisplayMemberPath="Name"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

我想从各个方面看到我的人,但我不知道如何显示它。