如何将保证金指定为百分比?

发布于 2024-09-27 03:39:59 字数 304 浏览 0 评论 0原文

我刚刚开始使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏至、离别 2024-10-04 03:39:59

以下是在 WPF 中实现 20% 左右边距的方法:

<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 就是围绕这一点而设计的。

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>

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.

好久不见√ 2024-10-04 03:39:59

您可以通过网格来完成此操作,而不是使用边距。

只需将控件放置在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文