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

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

问题描述

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

解决方案

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*" />

And likewise for rows -

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

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天全站免登陆