如何将保证金指定为百分比?
我刚刚开始使用 WPF。从那时起我就开始关注造型系统。我有 CSS 背景,我想以百分比形式设置边距。
<Style TargetType="TextBlock" x:Key="workflowNameTextBlock">
<Setter Property="Margin" Value="50"/>
</Style>
当前值以像素为单位设置,但我想将其设置为%,即50%。
我怎样才能实现这个目标?
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>
Currently value is set in pixels, but I would like to set it in %, i.e. 50%.
How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是在 WPF 中实现 20% 左右边距的方法:
如果您想要在 WPF 中重新实现简单的 CSS 布局,这可能看起来非常冗长,但那是因为实现简单的 CSS 布局确实不是问题所在WPF 就是围绕这一点而设计的。
Here's how you implement 20% left and right margins in 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.
您可以通过网格来完成此操作,而不是使用边距。
只需将控件放置在 Grid 元素中,并使用 3 列和 3 行。列/行大小可以按包含元素的百分比来完成。
Instead of using Margin, you can do this via a Grid.
Just place your control within a Grid element, and use 3 columns and 3 rows. The column/row sizing can be done as percentages of the containing element.