WPF How to set DataTemplate for DataGridCell dynamically

1k views Asked by At

I want make DataGrid, it will has 2 columns. First column has such a DataTemplate:

<DataGridTemplateColumn>
       <DataGridTemplateColumn.CellTemplate>
           <DataTemplate>
               <ComboBox>
                    <ComboBoxItem IsSelected="True">ComboBox Item #1</ComboBoxItem>
                    <ComboBoxItem >ComboBox Item #2</ComboBoxItem>
                    <ComboBoxItem >ComboBox Item #3</ComboBoxItem> 
               </ComboBox>
           </DataTemplate>
       </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

Second column must has more then one DataTemplate. First template - default template (does't matter what exactly). That template corresponds to ComboBox Item #1. Now imagine that you pick up second combobox item and DataTemplate of second column changes to DataTemplate, corresponds to ComboBox Item #2 item. For example, like that:

<DataTemplate>
    <TextBox FontSize="14"/> 
</DataTemplate>

The same about ComboBox Item #3. Pick up and DataTemplate of second column changes to DataTemplate, corresponds to that item. For example:

<DataTemplate>
    <ComboBox>
        <ComboBoxItem >Item 1</ComboBoxItem>
        <ComboBoxItem >Item 2</ComboBoxItem> 
    </ComboBox>
</DataTemplate>

I know about DataGridTemplateColumn.CellTemplateSelector and DataGrid.RowDetailsTemplateSelector classes. But it doesn't what I want :( Any idea?

0

There are 0 answers