I am trying to let the user choose in a combobox in the datagrid, but can not find the correct approach. I have tried using both binding and x:bind. What would be the best approach? I would imagine the following code to be correct, but I am missing something.
ViewModel
public partial class CustomerModel : ObservableObject
{
private ObservableCollection<DataType> _objects;
public ObservableCollection<DataType> Objects
{
get => _objects;
set => SetProperty(ref _objects, value);
}
public ObservableCollection<string> _test;
private ObservableCollection<string> _field;
public ObservableCollection<string> Field
{
get => _field;
set => SetProperty(ref _field, value);
}
public CustomerModel()
{
Objects = new();
Field = new ObservableCollection<string> { "Test", "Test" };
}
public class DataType : ObservableObject
{
public int ID { get; set; }
public string Name { get; set; }
public string Caption { get; set; }
public bool Numeric { get; set; }
public DataType()
{
}
}
}
.xaml
<controls:DataGrid
x:Name="dataGrid1" KeyDown="dataGrid1_KeyDown"
ItemsSource="{x:Bind Model.Objects}" AutoGenerateColumns="False" >
<controls:DataGrid.Columns>
<controls:DataGridComboBoxColumn Header="Field" ItemsSource="{x:Bind Model.Field}" Tag="Field"/>
</controls:DataGrid.Columns>
</controls:DataGrid>