I have customised a default ComboBox Style by using DataGrid in the popup (dropdown) as described here.
When I use the customised style in a ComboBox or in a DatagridComboBoxColumn, it works fine.
Similary when I use the style in the DataGridTemplateColumn.CellEditingTemplate, it works fine.
However, it does not work when used in a DataGridTemplateColumn.CellTemplate. The selection does not work at all. It is as if the selection changed event does not fire. I tried setting the IsSynchronizedWithCurrentItem="False" in the ComboBox, still it does not work.
Funny enough when I use the default ComboBox style in DataGridTemplateColumn.CellTemplate, it works. It appears the problem is when Datagrid is used as an ItemsHost.
The reason why I want to use it in a DataGridTemplateColumn.CellTemplate is because I want to change the look of my application by not using the standard DataGridComboBoxColumn where the editing part is hidden and one has to dig deeper to exopause the comboxbox. I want the user to click once to select items from the combobox.
Similarly the DataGridTemplateColumn is wired in such a way that the CellEditingTemplate is underneath the CellTemplate (which is similar to the default DatagridComboxBox). What I want instead is to use the DataGridTemplateColumn.CellTemplate for both viewing and selecting (editing).
At the same time I don't want to use the default ComboBox Style by replacing the ItemsHost with a Datagrid. But the customised style does not work in a DataGridTemplateColumn.CellTemplate. It only works in DataGridTemplateColumn.CellEditingTemplate
Any dies?
I resolved it by inserting these two lines in the Datagrid
SelectedItem="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem}" IsSynchronizedWithCurrentItem="False"