WPF调整内容问题 [英] WPF Resize contents issue

查看:67
本文介绍了WPF调整内容问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我不习惯使用wpf一段时间使用Windows窗体。我正在尝试创建一个基于屏幕大小调整大小的简单UI。然而,当我运行应用程序时,它通常只是关闭部分屏幕。在这种情况下,'lower_Border'必须
填充剩余的空间并调整其内部内容的大小,我无法做到这一点。

I am new to using wpf having used windows forms for a while. I am attempting to create a simple UI that resizes based on the screen size. However when I run the application it normally just cuts part of the screen off. In this case the 'lower_Border' must fill the remaining space and resize its internal contents, I can't get it to do this.

我附上了下面的代码。

I have attached the code below.

提前致谢

<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>

</UserControl>

推荐答案

虽然我不知道是什么你想要取得成果,但我可以给你一些建议。

如果你需要
自适应布局,
那么你不能使用
绝对大小。

If you need an adaptive layout,then you can not use the absolute size.

在您的代码中,您使用布局元素 网格 。然后你需要了解以下分配网格大小的方法可以指定为绝对逻辑单位数量,作为百分比值或自动。

In your code, you use layout element Grid. then you need understand the following ways to assign the size of grid can be specified as an absolute amount of logical units, as a percentage value or automatically.

        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="28" />

















已修复 固定大小的逻辑单位(1/96英寸)
自动 占用控件所需的空间
星级(*) 占用尽可能多的空间(填写所有自动和固定后)大小的列),按比例划分所有星形大小的列。所以3 * / 5 *表示与30 * / 50 *相同。请记住,如果网格大小是根据其
内容计算的,则星号大小不起作用。

在您的情况下,您的网格有两行全部由Auto分配,第一行是一个高度为100的boder,

Fixed Fixed size of logical units (1/96 inch)
Auto Takes as much space as needed by the contained control
Star (*) Takes as much space as available (after filling all auto and fixed sized columns), proportionally divided over all star-sized columns. So 3*/5* means the same as 30*/50*. Remember that star-sizing does not work if the grid size is calculated based on its content.

In your case, your Grid have two rows all assigned by Auto, the first row is a boder which height is 100,

如果你想要第二行占用屏幕的剩余空间 ,你应该设置
RowDefinition高度为*。

If you want the second row take the rest of space of screen, you should set RowDefinition Height to *.



并且边框中的网格不应设置高度,...
没有指定它,它将填满整个边界。

And the Grid in Border you should not set the height, ...Do not specify it, it will fill the entire border.

一个好的开始了解WPF布局系统将为您提供更多帮助

A good start to understand WPF layout system will help you more.

https://docs.microsoft.com / en-us / dotnet / framework / wpf / advanced / layout



https://www.wpftutorial.net/LayoutProperties.html

https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/layout

https://www.wpftutorial.net/LayoutProperties.html

希望这对您有所帮助并等待您的反馈。

Hope this is helpful to you and await your feed back.

此致,

Sincerely,

Bob


这篇关于WPF调整内容问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆