我在wpf中创建使用数据库并将值绑定到datagrid的程序。我有两个TabControl,而datagrid存在于第二个。我想在加载窗口后填充它并使第一列不可见。但是在填充之后,在选择第二个选项卡之前有些项目但没有列。为什么会这样?
这是我的xaml代码
<Window x:Class="AdminControl.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:AdminControl"
mc:Ignorable="d"
Title="MainWindow" Height="513.5" Width="994" Loaded="MainWindowLoaded">
<Grid>
<TabControl>
<TabItem Header="First">
<Grid>
<TextBox x:Name="Product_BarCode" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="Артикул" VerticalAlignment="Top" Width="120" Margin="32,28,0,0"/>
<TextBox x:Name="Product_Name" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Название" Width="120" Margin="185,28,0,191"/>
<TextBox x:Name="Product_Price" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="Цена" VerticalAlignment="Top" Width="120" Margin="185,114,0,0"/>
<TextBox x:Name="Product_Keywords" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="Ключевые слова" VerticalAlignment="Top" Width="120" Margin="32,114,0,0"/>
<TextBox x:Name="Product_TabTitle" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="Заголовок вкладки" VerticalAlignment="Top" Width="120" Margin="823,69,0,0"/>
<TextBox x:Name="Product_Description_Title" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="Заголовок Описания" VerticalAlignment="Top" Width="120" Margin="658,69,0,0"/>
<TextBox x:Name="Product_Link" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="ССылка" VerticalAlignment="Top" Width="120" Margin="494,69,0,0"/>
<TextBox x:Name="Product_Length" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="Длина" VerticalAlignment="Top" Width="120" Margin="32,69,0,0"/>
<TextBox x:Name="Product_Height" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="Высота" VerticalAlignment="Top" Width="120" Margin="823,28,0,0"/>
<TextBox x:Name="Product_Width" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="Ширина" VerticalAlignment="Top" Width="120" Margin="658,28,0,0"/>
<TextBox x:Name="Product_Weight" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Вес" Width="120" Margin="494,28,0,433"/>
<TextBox x:Name="Product_Count" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Количество" Width="120" Margin="337,28,0,191"/>
<TextBox x:Name="Product_Image" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="Название изображения" VerticalAlignment="Top" Width="152" Margin="337,114,0,0"/>
<TextBox x:Name="Product_Description" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="Описание" VerticalAlignment="Top" Width="120" Margin="185,69,0,0"/>
<TextBox x:Name="Product_SearchDescription" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="Описание Поисковика" VerticalAlignment="Top" Width="120" Margin="337,69,0,0"/>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="134,17,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
</Grid>
</TabItem>
<TabItem Header="Second">
<Grid>
<DataGrid x:Name="categoryGrid" HorizontalAlignment="Left" Margin="875,10,0,0" VerticalAlignment="Top" Height="388" Width="91" InitializingNewItem="categoryGridAddRow" IsEnabled="True"/>
<DataGrid x:Name="dataGrid" HorizontalAlignment="Left" VerticalAlignment="Top" Height="464" Width="860" Margin="10,10,0,-22" Grid.Column="0" Initialized="sadfasd"/>
<Button x:Name="button1" Content="Button" Margin="903,422,-2,0" VerticalAlignment="Top" Click="button1_Click"/>
</Grid>
</TabItem>
</TabControl>
</Grid>