I have a simple WPF window showing a button, TextBox and DataGrid . The DataGrid is filled from a multi column DataTable (reading an Excel sheet) with databinding : dg.DataContext:=dt.DefaultView. I do not know in advance how the table looks like (the user
can select any Excel sheet) so I can't predefine column widths.
When the users resizes the window, the DataGrid resizes with it but (when you make the window larger) the same content in the DataGrid remains visible (same number of cells) but only larger (larger font size). I want the DataGrid to show more columns and rows (if still available of course) when the DataGrid gets more space to display it, not to enlarge the existing view.
I've varied height/width and showing/not showing scrollbars, but without result.
How do I achieve that? This is the XAML:
<Viewbox Stretch="Uniform" StretchDirection="Both"><Grid><Button Content="Open Excel Sheet" HorizontalAlignment="Left" Margin="574,0,0,0" VerticalAlignment="Top" Width="210" Click="OpenExcelSheet_Click"/><DataGrid Name="dg" ItemsSource="{Binding}" HorizontalAlignment="Left" Height="375" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" VerticalAlignment="Top" Width="765" Margin="0,42,0,0"/><TextBox Name="tb" HorizontalAlignment="Left" Height="19" Margin="49,0,0,0" TextWrapping="Wrap" Text="--" VerticalAlignment="Top" Width="520" RenderTransformOrigin="3.98,0.09"/></Grid></Viewbox></Window>