I have a datagrid in XAML with 4 separate columns, all with *
for their width. All seems fine in Visual Studio with the control, everything looks good in the design view.
When I run my program however, all my columns shrink down to just 5 or so pixels of width, and nothing, not even clicking and dragging on the borders of the columns to resize them will change their width. Occasionally when I run my program I even see the columns start at their normal width, and then shrink down to their minimum size one pixel at a time over several seconds.
Upon some investigation, it seems that the issue is somehow related to using *
as the Width of the columns, as if I change all the columns to Auto
or a fixed width everything works fine in that column for some reason.
Below is the XAML code I'm having trouble with.
<GroupBox Header="header text" Margin="4"
Visibility="{Binding BindTarget, Converter={StaticResource BooleanToVisibilityConverter}}">
<DataGrid Margin="4" ItemsSource="{Binding}" DataContext="{Binding DataContextTarget}"
AutoGenerateColumns="False" MaxHeight="250" CanUserDeleteRows="False"
EnableRowVirtualization="False" CanUserSortColumns="True" CanUserResizeColumns="True">
<DataGrid.Columns>
<DataGridTemplateColumn Width="0.8*">
<DataGridTemplateColumn.Header>
<TextBlock Text="ResourceHeader1" TextWrapping="Wrap" />
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox
IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="True" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="*" IsReadOnly="True">
<DataGridTemplateColumn.Header>
<TextBlock Text="Name" TextWrapping="Wrap" />
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding FieldName1}" IsEnabled="True" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="*" IsReadOnly="True">
<DataGridTemplateColumn.Header>
<TextBlock Text="Model" TextWrapping="Wrap" />
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding FieldName2}" IsEnabled="True" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="*" IsReadOnly="True">
<DataGridTemplateColumn.Header>
<TextBlock Text="Manufacturer" TextWrapping="Wrap" />
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding FieldName3}" IsEnabled="True" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</GroupBox>
As you can see in the XAML, I even enabled letting users manually resize the column width in the datagrid, but that doesn't make a difference, the columns still refuse to be resized if I set their width to *
.
Any ideas what's causing this bizarre issue?