Try change type of ElementsSource
:
IObservable<>
to:
IList<>
like this:
public static readonly DependencyProperty ElementsSourceProperty =
DependencyProperty.Register(
"ElementsSource", typeof(IList<Type>), typeof(ListViewCustomControl),
null);
public IList<Type> ElementsSource
{
get { return (IList<Type>)GetValue(ElementsSourceProperty); }
set { SetValue(ElementsSourceProperty, value); }
}
For test, try set for ListView
name and write this line in code-behind:
MyListView.ElementsSource = data;
Version with Binding
In this case, you must specify the DataContext
, which would you want us to list:
XAML
<local:ListViewCustomControl Header="yolo"
ElementsSource="{Binding TestList}" />
Code-behind
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var testData = new TestData();
testData.TestList = new List<Type>();
for (var i = 0; i < 123; i++)
testData.TestList.Add(new Type(i));
this.DataContext = testData;
}
}
public class TestData
{
public List<Type> TestList
{
get;
set;
}
}
Some notes
You can choose the type of
IEnumerable
, because it is the base class for all collections.When you create a dependency property you can skip
PropertyMetadata
, in this case, the system will automatically assign a default value for this type.