Как адаптировать DataGrid под таблицу БД(SQL Server) в C#(WPF)
Есть TextBox в котором я пишу запрос и далее таблица появляется в datagrid, но я хочу что бы DataGrid была того же размера что и таблица, которая будет в запросе
XAML
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="ПРАКТИКА" Height="710" Width="800" Background="DarkGoldenrod">
<Grid Loaded="Grid_Loaded">
<TextBox x:Name="StateBtn1" HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="166" FontSize="14" Text="Состояния подключения" IsEnabled="False"/>
<Rectangle HorizontalAlignment="Left" Fill="Green" Height="23" Margin="181,10,0,0" Stroke="Black" VerticalAlignment="Top" Width="24"/>
<TextBox x:Name="codDolj" HorizontalAlignment="Left" Height="22" Margin="10,81,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="145" TextChanged="codDolj_TextChanged"/>
<TextBox x:Name="nameDolj" HorizontalAlignment="Left" Height="22" Margin="181,81,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="145" TextChanged="codDolj_TextChanged"/>
<Button x:Name="InsertBtn" Content="INSERT" HorizontalAlignment="Left" Margin="339,82,0,0" VerticalAlignment="Top" Width="61" FontWeight="Bold" FontSize="14" Click="InsertBtn_Click" IsEnabled="False"/>
<TextBox x:Name="SelectBox" HorizontalAlignment="Left" Height="101" Margin="10,165,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="316" TextChanged="SelectBox_TextChanged"/>
<Button x:Name="SelectBtn" Content="SELECT" HorizontalAlignment="Left" Margin="339,165,0,0" VerticalAlignment="Top" Width="61" FontWeight="Bold" FontSize="14" Click="SelectBtn_Copy_Click" IsEnabled="False"/>
<TextBlock HorizontalAlignment="Left" Height="14" Margin="10,144,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="105" FontWeight="Bold" TextDecorations="Underline"><Run Language="ru-ru" Text="Напишите запрос"/></TextBlock>
<DataGrid x:Name="DataGrid1" AutoGenerateColumns="True" HorizontalAlignment="Left" Height="141" Margin="10,283,0,0" VerticalAlignment="Top" Width="316"/>
</Grid>
</Window>