What I'm wanting to do is display the selected listview item's name 'if an item is selected' next to the 'Selected' label. I'm not entirely sure how to go about binding that, hope someone can help. Thank you.
XAML
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="240" Width="230">
<Grid>
<ListView Margin="10,10,10,43" Name="lvDataBinding">
<ListView.ItemTemplate>
<DataTemplate>
<WrapPanel>
<TextBlock Text="Name: " />
<TextBlock Text="{Binding Name}" FontWeight="Bold" />
<TextBlock Text=", " />
<TextBlock Text="Age: " />
<TextBlock Text="{Binding Age}" FontWeight="Bold" />
<TextBlock Text=" (" />
<TextBlock Text="{Binding Mail}" TextDecorations="Underline" Foreground="Blue" Cursor="Hand" />
<TextBlock Text=")" />
</WrapPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Label Content="Selected:" HorizontalAlignment="Left" Margin="10,172,0,0"/>
<Label Content="" HorizontalAlignment="Left" Margin="72,172,0,0" Width="140"/>
</Grid>
</Window>
CS
using System.Collections.Generic;
using System.Windows;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
List<User> items = new List<User>();
items.Add(new User() { Name = "John Doe", Age = 42, Mail = "[email protected]" });
items.Add(new User() { Name = "Jane Doe", Age = 39, Mail = "[email protected]" });
items.Add(new User() { Name = "Sammy Doe", Age = 13, Mail = "[email protected]" });
lvDataBinding.ItemsSource = items;
}
}
public class User
{
public string Name { get; set; }
public int Age { get; set; }
public string Mail { get; set; }
}
}