我的项目中有 2 个窗口。其中一个是 MainWindow.xaml,另一个是 Control_Page.xaml。我想将控制页面窗口插入到 ColumnDefinition 和 RowDefinition。此定义在 MainWindow 上定义。
这是我的代码:
<Grid x:Name="Grid_Main" SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="312*"/>
<ColumnDefinition Width="353*"/>
<ColumnDefinition Width="351*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="187*"/>
<RowDefinition Height="187*"/>
<RowDefinition Height="186*"/>
<RowDefinition Height="178*"/>
</Grid.RowDefinitions>
<Grid Grid.Column="0" Grid.Row="0" Margin="0"/>
<Grid Grid.Column="1" Margin="0"/>
<Grid Grid.Column="2" Margin="0"/>
<Grid Margin="0" Grid.Row="1"/>
<Grid Grid.Column="1" Margin="0" Grid.Row="1">
<Button Content="Button" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
<Grid Grid.Column="2" Margin="0" Grid.Row="1">
<Button x:Name="button1" Content="Button" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center"/>
</Grid>
<Grid Margin="0" Grid.Row="2"/>
<Grid Grid.Column="1" Margin="0" Grid.Row="2"/>
<Grid Grid.Column="2" Margin="0" Grid.Row="2"/>
<Grid Margin="0" Grid.Row="3"/>
<Grid Grid.Column="1" Margin="0" Grid.Row="3"/>
<Grid Grid.Column="2" Margin="0" Grid.Row="3"/>
</Grid>
我被称为 Var 的 Control_Page。然后像孩子一样尝试主窗口,但它不起作用。
我试过这个不能解决这个问题。
后面的代码;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var newWindow = new Control_Page();
Grid.SetRow(newWindow, 0);
Grid.SetColumn(newWindow, 0);
Grid_Main.Children.Add(newWindow);
}
}