WPF 星星有什么作用(宽度=“100*") [英] What does the WPF star do (Width="100*")

查看:41
本文介绍了WPF 星星有什么作用(宽度=“100*")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WPF 中星号在大小方面的确切含义是什么?

What does exactly the star in size terms in WPF mean?

推荐答案

在 WPF 网格中,Width="*"Height="*" 表示按比例调整大小.
例如:将 30% 分配给第 1 列,将 70% 分配给第 2 列 -

In a WPF Grid, Width="*" or Height="*" means proportional sizing.
For example: to give 30% to column 1 and 70% to column 2 -

<ColumnDefinition Width="3*" />
<ColumnDefinition Width="7*" />

同样对于行 -

<RowDefinition Height="3*" />
<RowDefinition Height="7*" />

数字不必是整数.
如果省略 RowDefinition 的宽度(ColumnDefinition 的高度),则隐含 1*.
在这个例子中,第 1 列比第 2 列宽 1.5 倍 -

The numbers do not have to be integers.
If the Width for RowDefinition (Height for ColumnDefinition) is omitted, 1* is implied.
In this example, column 1 is 1.5 times wider than column 2 -

<ColumnDefinition Width="1.5*" />
<ColumnDefinition />

您可以将自动调整宽度和固定宽度与 *(比例)宽度混合使用;在这种情况下,* 列在计算自动适应和固定宽度后分配给余数 -

You can mix auto-fit and fixed widths with * (proportional) widths; in that case the * columns are apportioned to the remainder after the auto-fit and fixed widths have been calculated -

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto" />  <!-- Auto-fit to content, 'Hi' -->
    <ColumnDefinition Width="50.5" />  <!-- Fixed width: 50.5 device units) -->
    <ColumnDefinition Width="69*" />   <!-- Take 69% of remainder -->
    <ColumnDefinition Width="31*"/>    <!-- Take 31% of remainder -->
</Grid.ColumnDefinitions>
<TextBlock Text="Hi" Grid.Column="0" />

这篇关于WPF 星星有什么作用(宽度=“100*")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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