I have the following class:
public class MyClass
{
public ObservableCollection<string> MyList { get; set; }
public string MyListTitle { get; set; }
...
I’m populating it as follows:
MyClass myClass = new MyClass("Data"); // Populates title
myClass.MyList.Add("Test data 1");
myClass.MyList.Add("Test data 2");
myListView.DataContext = MyClass.MyList;
Finally, here’s the XAML:
<ListView Visibility="Visible" x:Name="myListView" Height="Auto">
<ScrollViewer x:Name="contentScrollView">
<TextBlock x:Name="DataItem" Text="{Binding}" />
</ScrollViewer>
</ListView>
The result (and problem) is that I get the class name displayed once in the listview, rather than the two entries above.
You first need to set the
ItemsSourceproperty of theListViewto yourObservableCollectionAlso, you need to use a DataTemplate to display the actual items: