WPF-保证金百分比 [英] WPF - Margin in percentage
本文介绍了WPF-保证金百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚开始使用WPF.从那时起,我就开始关注样式系统.我来自CSS背景,我想按百分比设置边距.
I have just started using WPF. I'm getting my head around styling system since. I come from a CSS background and I would like to set margin in percentage.
<Style TargetType="TextBlock" x:Key="workflowNameTextBlock">
<Setter Property="Margin" Value="50"/>
</Style>
当前值以像素为单位设置,但我想以%(即50%)设置.
Currently value is set in pixels, but I would like to set it in %, i.e. 50%.
我该如何实现?
谢谢
推荐答案
以下是在WPF中实现20%左右边距的方法:
Here's how you implement 20% left and right margins in WPF:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="6*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1" Text="Hello, world."/>
</Grid>
如果您想做的是在WPF中重新实现简单的CSS布局,这似乎很荒谬,但这是因为实现简单的CSS布局实际上并不是WPF设计的空间问题.
This may seem ridiculously verbose if what you're trying to do is re-implement a simple CSS layout in WPF, but that's because implementing simple CSS layouts is really not the problem space WPF is designed around.
这篇关于WPF-保证金百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文