I'm writing an MVVM WPF app with a datagrid of values which needs to be editable. The meaning of the value varies depending on other data, so I've written a usercontrol for editing them with a template that varies depending on the type of value. i.e. it may appear as a textbox, a combobox, or one of several other inhouse controls that link to databases to retrieve possible values. This is the xaml I've used.
<DataGridTemplateColumn Header="Value">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<local:ValueViewingControl Value="{Binding Value}" ValueType="{Binding SettingValueType}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<local:ValueEditingControl Value="{Binding Value,Mode=TwoWay}" ValueType="{Binding SettingValueType}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
The problem is that once in editing mode, the next click on any part of the ValueEditingControl causes the cell to exit edit mode and go back to the ValueViewingControl before I can actually do anything. I assume its something to do with the cell thinking its lost focus. Does anyone know a way of keeping the cell in edit mode until I actually tab or click out of the cell?
[edit] A little more testing shows me that it works as expected if I use a textbox or a standard combobox as the edit control. This is making me think its the implementation of the custom controls I've written, which incorporate popups. When I select the popup that is part of the editing control, it thinks I've left the datagridcell and so ends editmode. How do I convince the datagridcell that the popup is inside it for focus purposes? It must be possible or the combobox wouldnt work.