MainPage.xaml
<Page
x:Class="UniversalAppTutorials.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UniversalAppTutorials"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel
x:Name="stack_panel1"
Margin="50"
Orientation="Vertical"
Background="Cornsilk"
Padding="50"
>
<ListView
x:Name="ListView1"
Header="Choose A Book"
SelectionChanged="ListView1_SelectionChanged"
>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Padding="5">
<TextBlock
Text="{Binding BookName}"
FontWeight="Black"
/>
<TextBlock
Text="{Binding Author}"
FontStyle="Italic"
/>
<TextBlock
Text="{Binding Price}"
Foreground="Crimson"
/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</Page>
MainPage.xaml.cs
using Windows.UI.Xaml.Controls;
using Windows.UI.Popups;
using System.Collections.Generic;
namespace UniversalAppTutorials
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
// Initialize a new list of books
List<Book> books = new List<Book>();
// Add some items to collection
books.Add(
new Book(
"Professional C# 6 and .NET Core 1.0",
"Christian Nagel",
"$60.00"
)
);
books.Add(
new Book(
"Beginning ASP.NET for Visual Studio 2015",
"William Penberthy",
"$45.00"
)
);
books.Add(
new Book(
"C# 24-Hour Trainer, 2nd Edition",
"Rod Stephens",
"$45.00"
)
);
books.Add(
new Book(
"Professional Visual Studio 2015",
"Bruce Johnson",
"$60.00"
)
);
// Specify the list view item source
ListView1.ItemsSource = books;
}
public class Book
{
public string BookName { get; set; }
public string Author { get; set; }
public string Price { get; set; }
public Book(string bookName, string author, string price) {
this.BookName = bookName;
this.Author = author;
this.Price = price;
}
}
private void ListView1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Get the instance of ListView
ListView listView = sender as ListView;
// Get the ListView selected item as a Book
Book selectedBook = listView.SelectedItem as Book;
// Initialize a new message dialog
MessageDialog dialog = new MessageDialog(
"Selected : \n"
+ selectedBook.BookName + "\n"
+ selectedBook.Author + "\n"
+ selectedBook.Price
);
// Finally, display the selected item details on dialog
dialog.ShowAsync();
}
}
}



- UWP - How to use TextBox SelectionChanged event
- UWP - How to use TextBox TextChanged event
- UWP - TextBox ScrollBar example
- UWP - How to create a multiline TextBox
- UWP - How to change TextBox background color
- UWP - SymbolIcon example
- UWP - How to add a new line to a TextBlock
- UWP - Get ComboBox selected item
- UWP - ListView multi select example
- UWP - ListView item style example
- UWP - How to change ListView item height
- UWP - ListView alternate item style
- UWP - How to create a ListView programmatically
- UWP - ListView Array ItemsSource example
- UWP - How to use ListView