我无法让我的 UserControl 正确填充/调整父窗口的大小。我正在使用 MVVM 编写 WPF 应用程序。我已经搜索了其他答案,但我无法弄清楚这一点。
主窗口.xaml
<Window x:Class="QiXR.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:QiXR.ViewModel"
xmlns:vw="clr-namespace:QiXR.View"
Title="MainWindow">
<Window.Resources>
<DataTemplate DataType="{x:Type vm:XRTestCaseListViewModel}">
<vw:XRTestCaseListView/>
</DataTemplate>
</Window.Resources>
<Grid>
<ItemsControl ItemsSource="{Binding ViewModels}" />
</Grid>
用户控制
<UserControl x:Class="QiXR.View.XRTestCaseListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<UserControl.Resources>
<Style x:Key="DataGridCheckBoxStyle" TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</UserControl.Resources>
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="160"/>
<ColumnDefinition Width="160"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
<RowDefinition Height="45"/>
</Grid.RowDefinitions>
这是我在 MainWindow 中启动 UserControl时显示的样子
是否可以在 UserControl 或 MainWindow 的 xaml 中执行此操作?谢谢