I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component public class AllViewComponent : ViewComponent { private readonly UserManager<ApplicationUser> _userManager; public AllViewComponent(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IViewComponentResult> InvokeAsync() { List<StudentViewModel> allUsers = new List<StudentViewModel>(); var items = await _userManager.Users.ToListAsync(); foreach (var item in items) { allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email }); }
Grid resource provides a way to reuse the objects and values by other controllers, as we studied in previous posts. In this article we will bind the listview with Grid resource defined in XAML code:
This resource is the same in our recent article about listbox binding with grid resource. Write the following code in XAML to bind the above resource:
When we run this project then it will bind the above data with listview as shown in following image:
To get selected item from this listview, write following code in the selectionChanged event of the listview:
Run the code and change the selection, a message box will display with the selected value.
<Grid.Resources>
<x:ArrayExtension Type="{ x:Type sys:String}" x:Key="placesSource">
<sys:String>London</sys:String>
<sys:String>Italy</sys:String>
<sys:String>California</sys:String>
<sys:String>France</sys:String>
</x:ArrayExtension>
</Grid.Resources>
<x:ArrayExtension Type="{ x:Type sys:String}" x:Key="placesSource">
<sys:String>London</sys:String>
<sys:String>Italy</sys:String>
<sys:String>California</sys:String>
<sys:String>France</sys:String>
</x:ArrayExtension>
</Grid.Resources>
This resource is the same in our recent article about listbox binding with grid resource. Write the following code in XAML to bind the above resource:
<ListView Name="listView" ItemsSource="{StaticResource placesSource}">
</ListView>
</ListView>
When we run this project then it will bind the above data with listview as shown in following image:
To get selected item from this listview, write following code in the selectionChanged event of the listview:
private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string selectedValue = listView.SelectedItem.ToString();
MessageBox.Show(selectedValue);
}
{
string selectedValue = listView.SelectedItem.ToString();
MessageBox.Show(selectedValue);
}
Run the code and change the selection, a message box will display with the selected value.
Comments
Post a Comment