1
votes

I've got a user control where the DataSource is an ObservableCollection<string>. If I set the DataSource of an instance of my user control via code it works

Chapters.DataSource = vm.ChapterList;

But trying to bind via ht xaml doesn't work

<b:ChapterStack x:Name="Chapters" DataSource="{Binding ChapterList}"></b:ChapterStack>

Other controls on the window are binding to the VM and displaying properly.

What do I have to do to get my usercontrol to bind via xaml?

thanks?

1
it ate my xaml: usercontrol x:Name="Chapters" DataSource="{Binding ChapterList}" - mike
xaml added in by editor, thanks - mike
Have you set the DataContext of the view to be an instance of your view model in XAML? - devdigital
For that given XAML line to work, vm needs to be there as a DataContext. Is it? Do you get any binding errors? Check your Output window. - decyclone
this.DataContext = _vm; //from xaml code behind - mike

1 Answers

0
votes

Make sure you defined the DataSource property of your ChapterStack control as a Dependency Property, because otherwise, you won't be able to bind it.