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 }); }
The same procedure will be follow up as in listbox binding. In the XAML define a combobox with some common properties you want as height, width and etc. Don’t forget the name property, because it will be used to assign itemsSource for this control.
<ComboBox Name="comboBox" Width="200"/>
Create a list of type string and add some items with Add() method of list. I have added the same items as in grid resources.
Just run the code and the same window will be shown with a combobox containing above four items.
Combobox also have a property selectedIndex which is used to get or set the selected index of the control. To select an item by default we can use this property as:
comboBox.SelectedIndex = 2;
Write the above line of code just below the c# code, and California will be selected.
<ComboBox Name="comboBox" Width="200"/>
Create a list of type string and add some items with Add() method of list. I have added the same items as in grid resources.
List<string> strList = new List<string>();
strList.Add("London");
strList.Add("Italy");
strList.Add("California");
strList.Add("France");
comboBox.ItemsSource = strList;
strList.Add("London");
strList.Add("Italy");
strList.Add("California");
strList.Add("France");
comboBox.ItemsSource = strList;
Just run the code and the same window will be shown with a combobox containing above four items.
Combobox also have a property selectedIndex which is used to get or set the selected index of the control. To select an item by default we can use this property as:
comboBox.SelectedIndex = 2;
Write the above line of code just below the c# code, and California will be selected.
Comments
Post a Comment