如何调整WPF列表视图比例? [英] How to resize WPF Listview proportionally?

查看:402
本文介绍了如何调整WPF列表视图比例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一点点问题,调整列表视图控件。我打算调整其大小比例,根据窗口的实际大小。

I have a little bit problem with resizing Listview control. I intend to make it resize proportionally, according to the actual size of the window.

有关的ListView初始大小,这是300 X 600(宽X高)像素。而且我还设置了了maxHeight ,以750,但它的宽度保持不变,即300

For initial size of Listview, it's 300 X 600 (width X height) in pixels. And I also set its maxHeight to 750, but its width stays the same, i.e. 300.

此外,在Wondow的属性,我已经改变了 SizeToContent 属性的 WidthAndHeight ,因为一些线程这样做建议你让系统决定控制的适当大小之后窗口的大小改变。

Also, in Wondow's properties, I have changed SizeToContent property to WidthAndHeight, as some of the threads suggest by doing so you let system decide the proper size of the control after window's been resized.

然而,它没有工作。所以我在这里寻求帮助。谢谢。

However, it's not yet working. So I am here to ask for help. Thanks.

P.S。反正是有,我们可以为宽度和高度设置WPF百分比值?这会是一个容易得多,如果我允许使用的百分比,如身高= 80%。

P.S. is there anyway we can set percentage value for width and height in WPF? That'd be a lot easier if I am allowed to use percentage, like height = 80%.

编辑:

要说得清楚,这里是在XAML一般code结构

To make it clearer, here is the general code structure in xaml

<Grid Height="Auto">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="50" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
    <StackPanel Grid.Row="0" Orientation="Horizontal" Height="Auto" Margin="0">
        <ListView />
    </StackPanel>
    <StackPanel Grid.Row="1" Orientation="Horizontal" Height="Auto" Margin="0">
        <Label />
        <Button /> 
    </StackPanel>
</Grid>

正如你所看到的,我目前使用2堆栈板,并把它们分开行。但列表视图仍然不能调整大小比例,即使我改变。

As you can see, I am currently using 2 stack panels and put them in separate rows. But Listview still can't resize proportionally even if I change to .

推荐答案

将您的ListView一个网格内,并使用*宽度功能对于列:

Place your ListView inside a Grid, and use the "*" width feature for the column:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="4*" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>

    <ListView Grid.Column="0">...</ListView>
</Grid>

在本实施例的列0具有的4 *的宽度和柱1具有1 *的缺省宽度。这意味着,他们之间它们共享的五颗星和列0带他们四个的宽度。这给你一个80%的宽度。

Column 0 in this example has a width of "4*" and column 1 has the default width of "1*". That means that between them they share a width of "five stars" and column 0 takes four of them. That gives you an 80% width.

这篇关于如何调整WPF列表视图比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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