today I've been struggling with proper binding and it seems like i can't figure out what is wrong with my approach. I have one basic window with ListView as it's main component. When I try to bind ListView's ItemSource to the ObservableCollection<> through XML, it seems like it doesn't work, but if I change the property through C# code, it works just fine. My guess would be it has something to do with visibility of the ObservableCollection<>, but whenever i try to make it public i get error that base class is less visible than the other class. Could anyone explain what am I missing here?
public partial class MainWindow : Window
{
public ObservableCollection<dataModel> items;
public MainWindow()
{
items = new ObservableCollection<dataModel>();
InitializeComponent();
populateData();
//LV1.ItemsSource = items; <= works with this uncommented
}
and XAML:
<ListView x:Name="LV1" HorizontalAlignment="Left" Height="264" Margin="55,59,0,0" VerticalAlignment="Top" Width="552" ItemsSource="{Binding items}">
<ListView.View>
<GridView>
<GridViewColumn Header="title" Width="200" DisplayMemberBinding="{Binding title}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
dataModel.cs:
public class dataModel
{
public string title { get; set;}
public bool isDone {get;set;}
}