How do I take a basic class that I've made and extract it's properties in the list in WPF? I've already tried playing with the itemssource property but nothing seems to have worked for me.
Public Class PageContent
Public StartDate As DateTime
Public Header As String
Public Content As String
End Class
<ListView Name="grid_PageContentList" >
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding StartDate}" Width="50"></GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Header}" Width="50"></GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Content}" Width="50"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
You cannot bind directly to fields, you need to use properties instead:
Also you need to ensure you have set you
DataContext
. If you have just a simple form with a code behind approach then put this in the constructor orLoaded
handler:And set your
ItemsSource
in your XAML:You need to make that an ObservableCollection with INPC or a DependencyProperty. Don't just bind regular properties like that as you might not see the data.