This question is locked. New answers and comments are not allowed.
I have a scenario where I need to change the content template of a cell on a row by row basis. Originally, the grid had two combo boxes. Country and State, and the states would be populated based on the country chosen by the user. As you can imaging if I have a two rows, one where country is Canada and one where the country is the US, the state column is going to be blank based on the last country that was selected.
Here is how I decided to tackle this issue:
I got rid of the combobox column and I'm just display plain text for the state in each row. What I would like on the current focused row is switch out the text box and replace it with a combo box that is populated with states based on the country of the current focused row. When that row loses focus, go back to the text box.
In the xaml, I created a data template that has the combo box. In my ViewModel I also created a TemplateSelector and Rules.
When the grid is loaded, I looped through the columns to find the state column and set it's CellTemplateSelector to the template selector in my view model. This all worked fine, except that the selector is called one time for every row when the ItemsSource is set.
I need to make it fire when the focused row changes.
I did see the example of the conditional data template, but it seems the only way to do that is define all of the columns in the xaml. I don't want to do this. We already have a binding mechanism that creates the columns.
Also, we are not putting the row into "Edit" mode. Currently it is displayed with empty text boxes and two combo boxes.
???
Thanks for your help!!
Here is how I decided to tackle this issue:
I got rid of the combobox column and I'm just display plain text for the state in each row. What I would like on the current focused row is switch out the text box and replace it with a combo box that is populated with states based on the country of the current focused row. When that row loses focus, go back to the text box.
In the xaml, I created a data template that has the combo box. In my ViewModel I also created a TemplateSelector and Rules.
When the grid is loaded, I looped through the columns to find the state column and set it's CellTemplateSelector to the template selector in my view model. This all worked fine, except that the selector is called one time for every row when the ItemsSource is set.
I need to make it fire when the focused row changes.
I did see the example of the conditional data template, but it seems the only way to do that is define all of the columns in the xaml. I don't want to do this. We already have a binding mechanism that creates the columns.
Also, we are not putting the row into "Edit" mode. Currently it is displayed with empty text boxes and two combo boxes.
???
Thanks for your help!!