0
這裏是我的頁面的XAML代碼的和平:WPF組合框結合
<ComboBox Grid.Row="2" Grid.Column="1" Name="Player2" MinWidth="50"
ItemsSource="{Binding PlayersTest}" DisplayMemberPath="ShortName">
自定義對象綁定到頁面數據方面:
page.DataContext = new SquadViewModel();
下面是部分SquadViewModel的」源代碼'class:
public class SquadViewModel
{
public SquadViewModel()
{
PlayersTest = new ObservableCollection<SostavPlayerData>();
PlayersTest.Add(new SostavPlayerData { ShortName = "A. Sereda", });
PlayersTest.Add(new SostavPlayerData { ShortName = "D. Sereda", });
}
public readonly ObservableCollection<SostavPlayerData> PlayersTest;
public string TestText { get { return "Binding works perfectly!"; } }
}
因此,ComboBox應該顯示一個對象列表,但它是空的。
您知道爲什麼以及如何獲得此列表嗎?
謝謝。
P.S.我試過其他XAML標記
<ComboBox Grid.Row="1" Grid.Column="1" Name="Player1" MinWidth="50"
ItemsSource="{Binding PlayersTest}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ShortName}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
它沒有也行,但結合簡單的文本塊:
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding TestText}"/>
完美的作品。
愚蠢的錯誤...... :(謝謝你的幫助,現在工作:) – Budda 2010-05-02 05:21:27