我需要将两个ListView
控件添加到ComboBox
项目,但它显示的列表视图项目而不是列表视图名称。怎样的ListView控件绑定到组合框的ItemSource
listView = new ListView();
ObservableCollection<String> list = new ObservableCollection<string>();
list.Add("1");
list.Add("2");
listView.ItemsSource = list;
listView2 = new ListView();
ObservableCollection<String> list12 = new ObservableCollection<string>();
list12.Add("11");
list12.Add("12");
listView2.ItemsSource = list12;
combobox.Items.Add(listView);
combobox.Items.Add(listView12);
private void combobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var combobox = sender as ComboBox;
if(combobox.SelectedIndex == 0)
combobox.ItemsSource = listView;
else
combobox.ItemsSource = listView12;
}
这里是我的XAML代码
<ComboBox Grid.Row="4" x:Name="combobox" SelectionChanged="combobox_SelectionChanged" />
您是否尝试过创建一个词典<字符串,列表>在这里你可以绑定的关键在于组合框? –
AbsoluteSith
我试过了,它不工作..我需要确切的答案 – shalusri