我不知道如何將飲料列表綁定到WPF TreeView。如何使用Xaml將列表綁定到WPF樹視圖?
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嗎?這種情況沒有多大意義。我認爲,在'popular'上設置排序的'ListBox'或'ListView'會更有意義。 – 2010-03-20 01:21:07
謝謝,你是對的,但我開始很簡單,因爲我不知道wpf,但後來實際上會用分層結構替換數據。 – 2010-03-20 01:22:55
@Benny:這個問題也引發了這個問題:http://stackoverflow.com/questions/2481010/how-to-bind-wpf-treeview-to-a-listdrink-programmatically – 2010-03-20 01:24:30