Файл MainWindow.xaml
<Window x:Class="WpfApp1.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:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<ListView ItemsSource="{Binding MyBooks}" Width="120">
<ListView.ItemTemplate>
<DataTemplate>
<Border BorderThickness="1,1,1,1" BorderBrush="DarkSlateGray" Background="Azure" Width="106">
<StackPanel>
<TextBlock Text="{Binding Path=BookName}"/>
<TextBlock Text="{Binding Path=BookPrice}"/>
</StackPanel>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Window>
Файл MainWindow.xaml.cs
using System.Collections.Generic;
using System.Windows;
namespace WpfApp1
{
public class Book
{
public string BookName { get; set; }
public long BookPrice { get; set; }
}
public partial class MainWindow : Window
{
public List<Book> MyBooks { get; set; } = new List<Book>();
public MainWindow()
{
MyBooks.Add(new Book() { BookName = "book1", BookPrice = 10 });
MyBooks.Add(new Book() { BookName = "book2", BookPrice = 20 });
MyBooks.Add(new Book() { BookName = "book3", BookPrice = 30 });
MyBooks.Add(new Book() { BookName = "book4", BookPrice = 40 });
MyBooks.Add(new Book() { BookName = "book5", BookPrice = 50 });
MyBooks.Add(new Book() { BookName = "book6", BookPrice = 60 });
MyBooks.Add(new Book() { BookName = "book7", BookPrice = 70 });
InitializeComponent();
// for binding
DataContext = this;
}
}
}