I\'m a beginner on WPF and trying to bind the Items of a ComboBox to an ObservableCollection
I used this code:
XAML
cmbContent
is null because you never set it to anything. I'm guessing the error is actually a NullReferenceException
, but it is showing up as TargetInvocationException
because it is in the constructor of a view.
Also, you're setting the ItemsSource
of the ComboBox
twice (once in the binding, once in the constructor). You don't need to do that. Pick one. Your binding won't work the way it is written (because the DataContext
isn't set) so you should either go with doing it in code, or set up the DataContext
(as suggested by Nadia).