Programming
WPF: DataGridTextColumn resizes automatically when editing an element
by admin on Mar.25, 2013, under Programming
Well I’ve ran into a problem today, where a DataGridTextColumn would always resize automatically whenever I edited an element.
Original textblock:
Textblock after double clicking it in order to edit the element:
Solution:
As a solution, all I did was to add the following code inside my <DataGridTextColumn>…</DataGridTextColumn> tag:
<DataGridTextColumn> <DataGridTextColumn.EditingElementStyle> <Style TargetType="{x:Type TextBox}"> <Setter Property="HorizontalAlignment" Value="Stretch" /> <Setter Property="TextAlignment" Value="Left" /> <Setter Property="Width" Value="{Binding ElementName=InstallationPathColumn, Path=ActualWidth}" /> <Setter Property="MinWidth" Value="200" /> </Style> </DataGridTextColumn.EditingElementStyle> </DataGridTextColumn>
This way I could also style the behaviour it would follow when editing an item. It’s of utter importance to add a DataGridTextColumn.EditingElementStyle block in order to accomplish this.
Final Result: