EDIT (clarification of requirements)
I have a DataGrid
as shown below. The values in the "Field Name To Store Old EmpNo" column change based on the value selected in "New EmpNo Rule" column. To accommodate this, each item in the DataGrid
ItemsSource
has its own TableNameForOldDataCollection
. I need to bind to this TableNameForOldDataCollection
and not a static property that cannot change.
If there is a way to do this binding while using DataGridComboBoxTemplate
I would prefer that. If not, I would like to know if it is possible to template the DataGridTemplateColumn
/ComboBox
to match that of the DataGridComboBoxTemplate
OP
I have a scenario where I am using DataGridComboBoxColumn
for one of the DataGrid
columns. In another column, I need to use the DataGridTemplateColumn
, with a ComboBox
, to properly bind to a dynamic ItemSource in the VM.
The DataGridComboBoxColumn
("New EmpNo Rule") is styled differently than the DataGridTemplateColumn
, with a ComboBox
("Field Name To Store Old EmpNo") as shown here:
How can I style the DataGridTemplateColumn
/ComboBox
to match the DataGridComboBoxColumn
, particularly how the combobox is hidden when the actual cell is not selected (like the second row of "New EmpNo Rule").
EDIT (added DataGrid
code):
<UserControl.Resources>
<ResourceDictionary>
<CollectionViewSource x:Key="StaticEmpNoRuleCollection" Source="{Binding EmpNoRuleCollection}" />
</ResourceDictionary>
</UserControl.Resources>
....
<DataGrid Name="DataGrid_MultiCompanyInfo"
ItemsSource="{Binding Model.EmpNoOptionsCollection}"
SelectedItem="{Binding SelectedEmpNoOptions}"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False">
<DataGrid.Columns>
<!-- Company -->
<DataGridTextColumn Header="Company"
Binding="{Binding Company}"
IsReadOnly="True" />
<!-- New EmpNo Rule -->
<DataGridComboBoxColumn Header="New EmpNo Rule"
Width="200"
ItemsSource="{Binding Source={StaticResource StaticEmpNoRuleCollection}}"
DisplayMemberPath="Description"
SelectedValueBinding="{Binding SelectedEmpNoRule, UpdateSourceTrigger=PropertyChanged}"/>
<!-- Field Name To Store Old EmpNo -->
<DataGridTemplateColumn Header="Field Name To
Store Old EmpNo"
Width="150" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox Name="OldEmpNo_ComboBox"
Margin="-5,0,0,0"
ItemsSource="{Binding TableNameForOldDataCollection}"
SelectedValue="{Binding TableNameForOldData, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
...
</DataGrid.Columns>
</DataGrid>