The Binding in the UserControl’s XAML should have the UserControl instance as its source object, e.g. like this:
<ListView ItemsSource="{Binding MessageList,
RelativeSource={RelativeSource AncestorType=UserControl}}" />
Alternatively you could set x:Name
on the UserControl and use an ElementName binding:
<UserControl ... x:Name="self">
...
<ListView ItemsSource="{Binding MessageList, ElementName=self}" />
...
</UserControl>
Besides that you should usually not set the DataContext of the UserControl to itself (like DataContext = this;
) because that would effectively prevent inheriting the DataContext from the UserControl’s parent element, which is necessary for an “external” binding to work, like:
<uc:RecentList MessageList="{Binding Messages}" />
3
solved How to bind List