WPF - Can't set combobox selectedIndex when itemssource changes?

You don't have any databinding to ComboBoxViewModel view model in your XAML, at least provided one. I think that is the problem.

Ah, can't believe I missed that. Thanks! – Justin984 Aug 1 at 19:53.

You need to bind your combobox to your VM. Public partial class MainWindow : Window { List list1 = new List() { "list 1", "list 1", "list 1" }; List list2 = new List() { "list 2", "list 2", "list 2" }; ComboBoxViewModel viewModel = new ComboBoxViewModel(); public MainWindow() { InitializeComponent(); cb_Test. DataContext = viewModel; } private void radioButton1_Click(object sender, RoutedEventArgs e) { viewModel.

ItemsSource = list1; viewModel. SelectedIndex = 0; } private void radioButton2_Click(object sender, RoutedEventArgs e) { viewModel. ItemsSource = list2; viewModel.

SelectedIndex = 0; } } and in XAML Even better design would be to move the code viewModel. ItemsSource = list1; viewModel. SelectedIndex = 0; to the VM itself.

Agree with Tigran. You need to assign the ComboBoxViewModel as the DataContext of the Window/Page/Control whatever this is AND you would need to bind SelectedIndex in the declaration of the ComboBox in the xaml. Since you need to bind, you should also move the List collections to one ViewModel with the SelectedIndex, and bind the ComboBox ItemsSource to a Property in your ViewModel that you can set under certain conditions.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions