So I have this class
public class User
{
public string Name { get; set; }
public int Age { get; set; }
public string ID { get; set; }
}
And my window has this ListView called "lvUsers" and a label called "label"
<ListView Margin="10,10,237,10" Name="lvUsers" SelectionChanged="idk">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="200" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Header="Age" Width="Auto" DisplayMemberBinding="{Binding Age}" />
</GridView>
</ListView.View>
</ListView>
<Label x:Name="label" Content="Label" HorizontalAlignment="Left" Margin="380,130,0,0" VerticalAlignment="Top"/>
Then I assigned the items like this
public static List<User> users = new List<User>();
public MainWindow()
{
InitializeComponent();
users.Add(new User() { Name = "John", Age = 42, ID = "H42"});
users.Add(new User() { Name = "Jacob", Age = 39, ID = "H39"});
users.Add(new User() { Name = "Richard", Age = 28, ID = "H28"});
lvUsers.ItemsSource = users;
}
And my question is: Is there a possibility that when I click an item in the ListView, the item's ID property will be displayed in a label called "label".
What I mean is that when I click on an item that says John and 42, I want label to say H42.
Is there a way to do it? Thank you very much for your time.