I have a DataGrid with two templates:
the first one includes a combobox, and I let it fit the size of its content, as it is no more than one or two words;
the second instead contains a text box where the text may become somewhat longer.
So here I set MaxWidth=somevalueto avoid expanding its width outside the datagrid container, I do the same for my own MaxHeightand set the text to wrap. In any case, I would like the text field to change width to fill all the remaining space in the datagrid container: if the user compresses or expands the second column, I would like the text field to decrease or increase accordingly, so that their width remains synchronized. The text will be wrapped and scroll bars will appear as needed.
Both controls in the grid are mapped to a data source in an MVVM script. Can someone give a hint for the width of the text field of the template to expand / contract using the container column? Here is my sample code:
<DataGrid ...>
<DataGrid.Columns>
<DataGridTemplateColumn ...>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox .../>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn ...>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox TextWrapping="Wrap"
MinWidth="400" MaxWidth="700"
MaxHeight="400"
ScrollViewer.VerticalScrollBarVisibility="Auto" .../>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>