开发者

WPF MVVM UserControl DataBinding in XAML Not Working

开发者 https://www.devze.com 2023-02-28 13:19 出处:网络
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

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开发者_JAVA技巧 are binding to the VM and displaying properly.

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

thanks?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号