I have implemented a datagrid with some datagrid columns.
One of these columns are a DatagridComboboxColumn. That has itemsource binding to an ObservableCollection list from my Viewmodel.
How do i update the itemsource, so i can see the new list on the UI? The list is changing from the getter, that means I can't use OnPropertyChange. Is there any way around updating the UI From ViewModel or what should be the way to go here?
ViewModel property:
private ObservableCollection<string> usedHMDGroups = new ObservableCollection<string>();
private ObservableCollection<string> startHMDGroups = new ObservableCollection<string>{
"136b6405",
"136b6406",
"136b6407",
"136b6408",
"136b6409",
"136b6410",
"None"
};
public ObservableCollection<string> HMDGroups
{
get
{
ObservableCollection<string> HMDGroupList = new ObservableCollection<string>(startHMDGroups.Except(usedHMDGroups));
return HMDGroupList;
}
set
{
OnPropertyChange("HMDGroups");
}
}
DatagridComboBoxColumn from datagrid:
<DataGridComboBoxColumn x:Name="hmdComboCol" Header="HMD Group"
SelectedValueBinding="{Binding HMDGroup, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding Path=HMDGroups, Mode=TwoWay, Source={StaticResource ComboItems}}"/>
I found out, that i could just set the itemsource of the column again to the same list. This will use the getter again.
hmdComboCol.ItemsSource = vhitems.HMDGroups;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.