Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF调整大小问题_C#_Wpf_Resize - Fatal编程技术网

C# WPF调整大小问题

C# WPF调整大小问题,c#,wpf,resize,C#,Wpf,Resize,我刚开始使用wpf,使用windows窗体已经有一段时间了。我正在尝试创建一个简单的UI,它可以根据屏幕大小调整大小。然而,当我运行应用程序时,它通常只是将屏幕的一部分切除。在这种情况下,“下边框”必须填充剩余空间并调整其内部内容的大小,我无法让它这样做。 我已经附上下面的代码。 提前谢谢 <UserControl x:Name="User_MainTemplate" x:Class="EventsUnlimited.UserControl2" xmlns="http:/

我刚开始使用wpf,使用windows窗体已经有一段时间了。我正在尝试创建一个简单的UI,它可以根据屏幕大小调整大小。然而,当我运行应用程序时,它通常只是将屏幕的一部分切除。在这种情况下,“下边框”必须填充剩余空间并调整其内部内容的大小,我无法让它这样做。 我已经附上下面的代码。 提前谢谢

<UserControl x:Name="User_MainTemplate" x:Class="EventsUnlimited.UserControl2"
         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" 
         xmlns:local="clr-namespace:EventsUnlimited"
         mc:Ignorable="d" 
         d:DesignHeight="{x:Static SystemParameters.PrimaryScreenHeight}" d:DesignWidth="{x:Static SystemParameters.PrimaryScreenWidth}">
<Grid Height="{x:Static SystemParameters.PrimaryScreenHeight}"  Width="{x:Static SystemParameters.PrimaryScreenWidth}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Border  HorizontalAlignment="Center" Height="100"  VerticalAlignment="Top" Width="{x:Static SystemParameters.PrimaryScreenWidth}" Background="#FF1291DA" />
    <Border x:Name="lower_Border"  HorizontalAlignment="Stretch"  Grid.Row="1" VerticalAlignment="Stretch" Background="#FF143199" >
        <Grid HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Height="1133" >
            <TabControl HorizontalAlignment="Stretch" Height="937"  VerticalAlignment="Stretch" Width="1872" >
                <TabItem Header="TabItem"/>
                <TabItem Header="TabItem">
                    <Grid Background="#FFE5E5E5"/>
                </TabItem>
            </TabControl>
        </Grid>

    </Border>
</Grid>


您有第二个
,需要将其设置为星号
。Auto将调整它以适应内容,star将调整它以填充。

在您的选项卡控件上,您为height指定了一个明确的值937,请尝试删除height=937

结果表明我对网格的理解是错误的。网格将调整元素之间的空间大小


要调整元素本身的大小,必须使用虚拟框并将元素放入其中。

对于这种排序,我通常使用停靠面板:这是我们在Windows窗体中使用的“Office应用程序设计”。我想我理解。自动将网格大小调整为元素的大小,并*使用所有可用空间?因此,要调整内容大小,您会使用viewbox吗?谢谢,ViewBox用于将内容缩放到特定大小并保持外观。就像在ViewBox中放置对象时可以设置字体大小一样,它们会增长/收缩到ViewBox的大小。我认为问题在于内容没有缩放到正确的大小,例如,选项卡控件没有更改以保持在边框的边界内。添加一个视图框修复了这个问题。我尝试过,但是当删除它时,它会设置有内容的区域的高度。然而,我需要它占据屏幕的一个设置区域,即使是空的。