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="AliceBlue"
Padding="50"
>
<ListView
x:Name="ListView1"
SelectionChanged="ListView1_SelectionChanged"
>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel
Orientation="Horizontal"
Margin="0"
BorderBrush="LightSkyBlue"
BorderThickness="0,0,0,2"
Padding="5,5,5,5"
>
<Image
Source="{Binding Image}"
Margin="10,10,20,10"
/>
<StackPanel Orientation="Vertical">
<TextBlock
Text="{Binding BookName}"
FontWeight="Black"
Margin="0,30,0,0"
FontFamily="Calibri"
FontSize="17"
/>
<TextBlock
Text="{Binding Author}"
FontStyle="Italic"
/>
<TextBlock
Text="{Binding Price}"
Foreground="Crimson"
/>
</StackPanel>
</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",
"Assets/professional_c_sharp_6_and_dot_ner_core_1.jpeg"
)
);
books.Add(
new Book(
"Beginning ASP.NET for Visual Studio 2015",
"William Penberthy",
"$45.00",
"Assets/beginning_asp_dot_net_for_visual_studio_2015.jpeg"
)
);
books.Add(
new Book(
"C# 24-Hour Trainer, 2nd Edition",
"Rod Stephens",
"$45.00",
"Assets/c_sharp_24_hour_trainer_2nd_edition.jpeg"
)
);
books.Add(
new Book(
"Professional Visual Studio 2015",
"Bruce Johnson",
"$60.00",
"Assets/professional_visual_studio_2015.jpeg"
)
);
// 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 string Image { get; set; }
public Book(string bookName, string author, string price, string image)
{
this.BookName = bookName;
this.Author = author;
this.Price = price;
this.Image = image;
}
}
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 - SymbolIcon example
- UWP - How to add a new line to a TextBlock
- UWP - How to bold text in a TextBlock
- UWP - PivotItem header with image and text
- UWP - Simple Pivot example
- UWP - Border example
- UWP - Polygon example
- UWP - Rectangle example
- UWP - Add border to an Ellipse
- UWP - Get ComboBox selected item
- UWP - ListView multi select example
- UWP - ListView HeaderTemplate example
- UWP - How to add margin to each item in a ListView
- UWP - CheckBox group example
- UWP - Button click event