我已经定义一个类,如:如何将数据从DataContext传递到WPF中的ListBox?
public class Agent
{
public int Id { get; set; }
public string Category { get; set; }
// rest removed for brevity
}
然后,在WPF中,我得到的数据作为List
并将它传递给DataContext
就象这样:
List<Agent> agents; // this includes my data
this.DataContext = agents;
而在.xaml
部分我想列出每个对象的Category
字段。我有这样的事情:
<ListBox
Name="agentCategoryListBox"
Grid.Row="2"
Grid.Column="1"
ItemSource="{Binding Path=Category"} />
但是,这似乎并没有正常工作。有任何想法吗?
你正在使用什么? – Valkyrie