I have a usercontrol containing some buttons and a ListView.
I want my custom control to have an ItemsSource
property that binds to the listviews itemsource directly.
MyControl.xaml.cs
public partial class MyControl : UserControl
{
public static DependencyProperty ItemsSourceProperty =
ListView.ItemsSourceProperty.AddOwner(typeof(AddFilesControl));
public ObservableCollection<DocumentFile> ItemsSource
{
get { return (ObservableCollection<DocumentFile>)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
}
MyControl.xaml
<UserControl x:Class="[...].MyControls.MyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008">
<Grid>
<ListView>
<ListView.ItemTemplate>
[...]
</ListView.ItemTemplate>
</ListView>
</Grid>
</UserControl>
MyViewModel.cs (set as the DataSource of MyWindow
containing only MyControl
)
public class MyViewModel : INotifyPropertyChanged
{
public ObservableCollection<DocumentFile> DefaultList { get; set; }
}
When debugging no items are displayed, but there are items in the ViewModel.
The Binding seems to be correct.
<custom:MyControl ItemsSource="{Binding DefaultList}" />
What is wrong here ?