Вот очень простой пример, который вы можете расширить для своих целей. Пожалуйста, дайте мне знать, если у вас возникли проблемы с пониманием чего-либо.
MainWindow.xaml
<Window x:Class="WpfApp5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp5"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<ListView Width="740" Height="400" ItemsSource="{Binding MyListItems}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=Title}"
Header="Title" />
<GridViewColumn DisplayMemberBinding="{Binding Path=Description}"
Header="Description" />
<GridViewColumn DisplayMemberBinding="{Binding Path=ReleaseDate}"
Header="Release" />
</GridView>
</ListView.View>
</ListView>
</Grid>
MainWindow.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = new MyClass();
}
}
ViewModel
public class MyClass : INotifyPropertyChanged
{
private ObservableCollection<MyListItem> _myListItems;
public ObservableCollection<MyListItem> MyListItems
{
get => _myListItems;
set
{
_myListItems = value;
OnPropertyChanged(nameof(MyListItems));
}
}
public MyClass()
{
MyListItems = new ObservableCollection<MyListItem>();
MyListItems.Add( new MyListItem()
{
Title = "Title1",
Description = "This is description nr1",
ReleaseDate = DateTime.Now
} );
MyListItems.Add( new MyListItem()
{
Title = "Title2",
Description = "This is description nr2",
ReleaseDate = DateTime.Now
} );
MyListItems.Add( new MyListItem()
{
Title = "Title3",
Description = "This is description nr3",
ReleaseDate = DateTime.Now
} );
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged( [CallerMemberName] string propertyName = null )
{
PropertyChanged?.Invoke( this, new PropertyChangedEventArgs( propertyName ) );
}
И класс, который представляет одну запись в вашем списке:
public class MyListItem : INotifyPropertyChanged
{
private string _title;
public string Title
{
get => _title;
set
{
_title = value;
OnPropertyChanged( nameof( Title ) );
}
}
private string _description;
public string Description
{
get => _description;
set
{
_description = value;
OnPropertyChanged( nameof( Description ) );
}
}
private DateTime _releaseDate;
public DateTime ReleaseDate
{
get => _releaseDate;
set
{
_releaseDate = value;
OnPropertyChanged(nameof(ReleaseDate));
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged( [CallerMemberName] string propertyName = null )
{
PropertyChanged?.Invoke( this, new PropertyChangedEventArgs( propertyName ) );
}
}
Если вы ищете в Google «MVVM» и «Wpf Databinding», вы найдете множество учебных пособий и примеров.