在调整主窗口大小时,如何使页面始终适合框架? WPF

时间:2018-02-08 16:05:20

标签: c# wpf xaml responsive

我的MainWindow有3个网格列,2°和3°列内有一个框架,两个框架都包含页面。

MainWindow.xaml

<Window [the usual stuff]
    Title="p" Height="1080" Width="1920" WindowStartupLocation="CenterScreen" WindowStyle="ThreeDBorderWindow" Background="White" WindowState="Maximized">
<Grid x:Name="MainGrid">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="10*" />
        <ColumnDefinition Width="35*" />
        <ColumnDefinition Width="55*" />
    </Grid.ColumnDefinitions>

    <Grid Grid.Column="0" Background="DarkGreen">

        <Button x:Name="ControlButton" Content="Control" HorizontalAlignment="Left" Margin="39,214,0,0" VerticalAlignment="Top" Width="116" Height="42" Click="ControlButton_Click"/>
    </Grid>
    <Grid Grid.Column="1" Background="DarkSalmon">
        <Frame x:Name="MainFrame" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" NavigationUIVisibility="Hidden"/>
    </Grid>
    <Grid Grid.Column="2" Background="DarkTurquoise">
        <Frame x:Name="ChartFrame" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" NavigationUIVisibility="Hidden"/>
    </Grid>
</Grid>
</Window>

我将网格列设置为数字*,以便在调整窗口大小时自动调整大小。所以我知道第一帧大小是窗口宽度的35%,我如何为帧所承载的页面设置相同的东西。

Page.xaml

<Page [usual stuff]
  d:DesignHeight="1049" d:DesignWidth="669"
  Title="FirstPage">

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100*" />
    </Grid.ColumnDefinitions>
    <Grid Grid.Column="0">
        <Button x:Name="LangButton" Content="English" HorizontalAlignment="Left" Margin="715,26,0,0" VerticalAlignment="Top" Width="75" Click="LangButton_Click"/>
    </Grid>
</Grid>
</Page>

页面的宽度和高度设置只是因为我没有放在那里。我希望在调整MainWindow的大小时,我页面中的内容会调整大小以适应框架尺寸。

0 个答案:

没有答案