在TabItem/StackPanel中自动调整WPF框架对象的大小
我希望框架控件自动调整大小以填充选项卡项内的屏幕。是下面的代码,它呈现一个非常小的帧。我宁愿不设置静态高度和宽度。这是XAML在TabItem/StackPanel中自动调整WPF框架对象的大小,wpf,frame,autosize,Wpf,Frame,Autosize,我希望框架控件自动调整大小以填充选项卡项内的屏幕。是下面的代码,它呈现一个非常小的帧。我宁愿不设置静态高度和宽度。这是XAML <TabItem Header="Reports" Name="tReports" Height="50" BorderBrush="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="100"> <Grid>
<TabItem Header="Reports" Name="tReports" Height="50" BorderBrush="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="100">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<ComboBox Grid.Row="0" Name="cmbReport" Width="200" HorizontalAlignment="Left" />
<Frame Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Source="http://online/home/" Margin="0,15,0,0" />
</Grid>
</TabItem>
这是可行的,关键部分不是设置第二行definition Height=“Auto”,而是需要设置第一行,否则框架只占屏幕的1/2左右,如图所示
<TabItem Header="Reports" Name="tReports" Height="50" BorderBrush="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="100">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<ComboBox Grid.Row="0" Name="cmbReport" Width="200" HorizontalAlignment="Left">
</ComboBox>
<Frame Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Source="http://online/home/" Margin="0,15,0,0" />
</Grid>
</TabItem>
谢谢,这很有帮助。我还需要提到的是,我必须在TabItem控件中添加另一个控件。一旦我创建了另一个控件,框架就不会垂直填充。有关更新XAML,请参阅我的原始问题。
<TabItem Header="Reports" Name="tReports" Height="50" BorderBrush="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="100">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<ComboBox Grid.Row="0" Name="cmbReport" Width="200" HorizontalAlignment="Left">
</ComboBox>
<Frame Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Source="http://online/home/" Margin="0,15,0,0" />
</Grid>
</TabItem>