I have a ComboBox and want to prepopulate the value in the ComboBox to a preset value.
I have a list of food categories, which is an ObservableCollection called ItemCategories, which is a property. The list has 5 different types.
I also have a selected category property called ItemCategory of type ItemCategory.
ItemCategory has two properties, Category and PK_ItemCategoryId.
So far this is what I have
The combobox's ItemSource is bound to a property in the ViewModel.
private ObservableCollection<ItemCategory> _itemCategories;
public ObservableCollection<ItemCategory> ItemCategories
{
get
{ return _itemCategories; }
set
{
_itemCategories = value;
OnPropertyChanged("ItemCategories");
}
}
private ItemCategory _itemCategory;
public ItemCategory ItemCategory
{
get { return _itemCategory; }
set
{
_itemCategory = value;
OnPropertyChanged("ItemCategory");
}
}
What I want to do, when the user opens the app is to prepopulate the value in the combox witha an item in the list. Below is an example what I want to achieve.
How can I acheive this using MVVM and WPF?