我想我的组合绑定列表,但我什么也没有为什么我的组合框绑定不工作
public MainWindow()
{
DataContext = this;
InitializeComponent();
List<item> list = new List<item>();
list.Add(new item() {id = 1,name = "stack"});
list.Add(new item() { id = 2, name = "overflow" });
comboBox.DataContext = list;
comboBox.SelectedIndex = 0;
}
<ComboBox x:Name="comboBox" HorizontalAlignment="Left" Margin="22,14,0,0" VerticalAlignment="Top" Width="147"
ItemsSource="{Binding Path=list}" >
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Path=id}" />
<Label Content=":" />
<Label Content="{Binding Path=name}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
不要插入链接到外部网站。在这里发布代码的相关部分。 – Steve
其带我有时小时,以适应我的代码到stackoverflow要求 – user4515101