I have noticed DataGrid columns in my project do not stretch to DataGrid width any more. The only thing I did is changed Assmbly name. In XAML designer they are stretched.
<DataGrid x:Name="dg" Grid.Row="4" RowHeaderWidth="0" AutoGenerateColumns="False"
HorizontalGridLinesBrush="AliceBlue" AlternationCount="2">
<DataGrid.Columns>
<DataGridTemplateColumn Header="File" IsReadOnly="True" Width="*" CanUserSort="True" SortMemberPath="File" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=FileName}" MouseDown="FileName_MouseDown" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
//other columns are similar
</DataGrid.Columns>
</DataGrid>
What I have tried:
Rebuild solution
Delete "bin" folder and rebuild
I used old version which was OK, and changed Assembly name (which was only difference between backups) and I compared all files between these two versions (in codecompare and notepad++, one by one) and all files were the same but one stretches and the other doesn't. Both version too are old so I can not go back.
Create new Datagrid with just ColumnWidth="*" AutogenerateColumns="True"
HorizontalContentAlignment="Stretch" and HorizontalAlignment="Stretch"
I ran of ideas. Please offer any idea no matter if silly. Thanks!
I solved it:
The only difference was that I had on good version MyWindow.Show();
after initialization. I tried several times commenting and uncommenting this line and this is was the fix.
MyWindow is just name of the windows defined in xaml, and show() does not do anything since window is visible anyway.
If anyone else has this problem just add WindowName.Show()
after InitializeComponent();
I pronounce it a bug unless one of you can think of the reason.