How to open a User Control on click a row ??

Oct 6 2017 3:56 AM
I want to open a new user control if I click on any row? How to do this please help me.
 
 
MainWindow.xaml
  1. <Grid>  
  2. <ListView Margin="10" Name="lvUsers">  
  3. <ListView.View>  
  4. <GridView>  
  5. <GridViewColumn Header="Name" Width="120" DisplayMemberBinding="{Binding Name}" />  
  6. <GridViewColumn Header="Age" Width="50" DisplayMemberBinding="{Binding Age}" />  
  7. <GridViewColumn Header="Mail" Width="150">  
  8. <GridViewColumn.CellTemplate>  
  9. <DataTemplate>  
  10. <TextBlock Text="{Binding Mail}" TextDecorations="Underline" Foreground="Blue" Cursor="Hand"/>  
  11. </DataTemplate>  
  12. </GridViewColumn.CellTemplate>  
  13. </GridViewColumn>  
  14. <GridViewColumn Header="Next Menu" Width="Auto">  
  15. <GridViewColumn.CellTemplate>  
  16. <DataTemplate>  
  17. <Button Content="Details"/>  
  18. </DataTemplate>  
  19. </GridViewColumn.CellTemplate>  
  20. </GridViewColumn>  
  21. </GridView>  
  22. </ListView.View>  
  23. </ListView>  
  24. </Grid>  
MainWindow.xaml.cs
  1. namespace Listview  
  2. {  
  3. /// <summary>  
  4. /// Interaction logic for MainWindow.xaml  
  5. /// </summary>  
  6. public partial class MainWindow : Window  
  7. {  
  8. public MainWindow()  
  9. {  
  10. InitializeComponent();  
  11. List<User> items = new List<User>();  
  12. items.Add(new User() { Name = "John Doe", Age = 42, Mail = "[email protected]" });  
  13. items.Add(new User() { Name = "Jane Doe", Age = 39, Mail = "[email protected]" });  
  14. items.Add(new User() { Name = "Sammy Doe", Age = 7, Mail = "[email protected]" });  
  15. lvUsers.ItemsSource = items;  
  16. }  
  17. }  
  18. public class User  
  19. {  
  20. public string Name { getset; }  
  21. public int Age { getset; }  
  22. public string Mail { getset; }  
  23. }  
  24. }  

Answers (2)