0
votes

I have a WPF DataGrid with a few radio button columns and a couple of textbox columns.

All columns are DataGridTemplateColumns so I can customize the string display formatting. (Not sure if this has any bearing on anything.)

There are two columns with radio buttons that are supposed to be grouped together to allow the user to select one, or the other.

In the view model behind a row, there is code that generates a unique groupname for the pair of radio buttons so that each row has its own set of mutually exclusive options.

The problem is, it seems that the DataGrid doesn't instantiate the row's viewmodel until a textbox is activated. That's when the constructor is triggered. Until that point, there is no unique groupname so a user can select both radio buttons. Once the constructor runs, the radio buttons behave properly.

Is there a way to force the viewmodel to be instantiated as soon as the DataGrid displays the new row?

1

1 Answers

0
votes

The radio buttons should have a command that you can bind to - allowing you to programmatically instantiate the view model. You could send the datacontext of the row as the parameter of the command (this may even force instantiation), and then you could instantiate it and add it to the collection that the DataGrid is using as a DataSource if it is still null.