简体   繁体   English

如何在WPF(3个控件)中创建此布局?

[英]How to create this layout in WPF (3 controls)?

在此处输入图片说明

I made this image that shows the controls. 我制作了显示控件的图像。 The top one is a ListView and the others are ListView controls as well with additional controls. 最上面的一个是ListView ,其他的是ListView控件以及其他控件。

But I can't figure out how to layout them to look like that. 但是我不知道如何布局它们。

Currently I use 3 DockPanels for each ListView where the top one uses Top VerticalAlignment , the others use Bottom for VerticalAlignment , Left and Right (for HorizontalAlignment ). 目前,我为每个ListView使用3个DockPanels ,其中最上面的一个使用Top VerticalAlignment ,其他的使用Bottom分别用于VerticalAlignment ,Left和Right(对于HorizontalAlignment )。

But when I look at it, the other 2 controls appear after the top ListView to its right side. 但是当我查看它时,其他2个控件出现在顶部ListView右侧之后。 I can see this when I scale the top DockPanel to half the size, then the other 2 DockPanels show up, attached to the top DockPanel's right side. 当我将顶部的DockPanel缩放到一半大小时,我看到了这一点,然后显示了另外两个DockPanel,它们附加在顶部的DockPanel的右侧。

Any ideas on how to fix this? 有想法该怎么解决这个吗?

How about this? 这个怎么样?

The grid has no fixed widths or heights and should accommodate whatever controls you add. 网格没有固定的宽度或高度,应该可以容纳您添加的任何控件。

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
        <ColumnDefinition Width="*"></ColumnDefinition>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Background="Aqua" Height="100"/>
    <StackPanel Grid.Row="2" Grid.Column="0" Background="Orange" Height="100" Width="150" VerticalAlignment="Bottom"/>
    <StackPanel Grid.Row="2" Grid.Column="2" Background="Green" Height="60" Width="200" VerticalAlignment="Bottom"/>
</Grid>

Initial window 初始窗口

在此处输入图片说明

Resized window 调整大小的窗口

在此处输入图片说明

EDIT in response to comment 编辑以回应评论

If you want a progressbar in the top panel, just use: 如果要在顶部面板中使用进度条,请使用:

    <StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" 
       Background="Aqua" Orientation="Vertical">
        <ListView Height="50" Background="Purple"></ListView>
        <ProgressBar Height="20" IsIndeterminate="True" ></ProgressBar>
    </StackPanel>

在此处输入图片说明

Do you need them to be DockPanels, or this is a fixed layout? 您需要它们成为DockPanels,还是固定布局?

If it's fixed you could do something like this: 如果已修复,则可以执行以下操作:

<Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="80"></RowDefinition>
      <RowDefinition Height="*"></RowDefinition>
      <RowDefinition Height="50"></RowDefinition>
      <RowDefinition Height="50"></RowDefinition>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="100"></ColumnDefinition>
      <ColumnDefinition Width="*"></ColumnDefinition>
      <ColumnDefinition Width="200"></ColumnDefinition>
    </Grid.ColumnDefinitions>
<ListView Grid.Row="0" Grid.RowSpan="1" Grid.Column="0" Grid.ColumnSpan="3" Name="dockPanel1" Background="CadetBlue">
    </ListView>
    <ListView Grid.Row="2" Grid.RowSpan="2" Name="dockPanel2" Background="Cyan">
    </ListView>
    <ListView Grid.Row="3" Grid.RowSpan="1" Grid.Column="2" Name="dockPanel3" Background="DarkRed">
    </ListView>
  </Grid>

I made the area between your three panels re-sizable as your window resizes. 我调整了三个面板之间的区域,以调整窗口大小。

Instead of the listviews that I used, you can put pretty much anything, a user control, another grid, whatever. 除了我使用的列表视图之外,您还可以放置几乎所有内容,用户控件,其他网格等。

The colors will show you where the listview sections are easily. 颜色将向您显示列表视图部分的位置。

You will probably want to adjust the sizes, or change the resize behavior. 您可能需要调整大小或更改调整大小行为。

You can learn more about grids here 您可以在此处了解有关网格的更多信息

似乎是这种情况,例如对齐,边距和填充可以处理...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM