To bind a DataGridComboBoxColumn to an ObservableCollection, you can follow these steps:
public ObservableCollection<string> MyCollection { get; set; }
MyCollection = new ObservableCollection<string>();
MyCollection.Add("Item1");
MyCollection.Add("Item2");
MyCollection.Add("Item3");
<DataGridComboBoxColumn Header="My Combo Column"
SelectedItemBinding="{Binding SelectedItemProperty}"
ItemsSource="{Binding MyCollection}"
DisplayMemberPath="."/>
private string _selectedItem;
public string SelectedItemProperty
{
get { return _selectedItem; }
set
{
_selectedItem = value;
OnPropertyChanged(nameof(SelectedItemProperty));
}
}
public class MyViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public MainWindow()
{
InitializeComponent();
DataContext = new MyViewModel();
}
With these steps, you will be able to bind your DataGridComboBoxColumn to your ObservableCollection.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-09-03 11:00:00 +0000
Seen: 10 times
Last updated: Apr 15 '22
How can ListView in Maui be refreshed automatically?
What steps do I need to follow to create an ObservableCollection property that is read-only?
What is the method to reach my ViewModel from the code behind?
How can I obtain a viewmodel when using hilt in UnitTest?
What are the steps for modifying DataGrid AutoGenerateColumns() using MVVMCross?
When a fragment is destroyed, why isn't the Android ViewModel also destroyed?
What is the method to use Hilt for injecting a list into a ViewModel?