【发布时间】:2010-03-20 09:18:16
【问题描述】:
我不知道如何将饮料列表绑定到 WPF TreeView。
struct Drink
{
public string Name { get; private set; }
public int Popularity { get; private set; }
public Drink ( string name, int popularity )
: this ( )
{
this.Name = name;
this.Popularity = popularity;
}
}
List<Drink> coldDrinks = new List<Drink> ( ){
new Drink ( "Water", 1 ),
new Drink ( "Fanta", 2 ),
new Drink ( "Sprite", 3 ),
new Drink ( "Coke", 4 ),
new Drink ( "Milk", 5 ) };
}
}
我在网上搜索过,例如看到here。但这甚至意味着什么:ItemsSource="{x:Static local:TreeTest.BoatList}"
x:? static? local?
如何在 xaml 的代码中指定集合?
【问题讨论】:
-
您的数据不是分层的。你真的想使用 TreeView 吗?在这种情况下没有多大意义。我认为
ListBox或ListView在popularity上设置排序会更有意义。 -
谢谢,你是对的,但我开始很简单,因为我不知道 wpf,但稍后实际上会用分层数据替换数据。
-
@Benny:在这个问题上也提出了这一点:stackoverflow.com/questions/2481010/…
-
@Reed 嗯是的。难怪,因为这两个问题几乎相同,而且是由同一个人提出的。