WPF 的 XAML 中的保证金百分比
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20927678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Margin as percentage in WPF's XAML
提问by Yoda
I would like to make a UniformGrid take 70% of total window width and 80% of total window height. How achieve it?
我想让 UniformGrid 占据总窗口宽度的 70% 和总窗口高度的 80%。如何实现?
<UniformGrid x:Name="Grid" Margin="20,0,0,0">
</UniformGrid>
回答by Eugene
Like the other answer suggests, you first create a Grid like so:
就像另一个答案所暗示的那样,您首先像这样创建一个网格:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="8*" />
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="7*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<UniformGrid x:Name="yourGrid">
</UniformGrid>
</Grid>
Then you set your UniformGrid control as the child in the 0th row 0th column of the main grid. The x* notation means that you want x parts of the screen used in the row/column, so splitting rows at 8*/2* splits them at 80%/20% and splitting columns and 7*/3* splits them at 70%/30%. I hope that clears it up for you.
然后将 UniformGrid 控件设置为主网格第 0 行第 0 列中的子项。x* 表示法意味着您希望在行/列中使用屏幕的 x 部分,因此在 8*/2* 处拆分行将它们拆分为 80%/20% 并将列拆分为 7*/3* 将它们拆分为 70 %/30%。我希望这可以为您解决问题。

