【问题标题】:0.5px margin between RowDefintions?RowDefintions 之间的 0.5px 边距?
【发布时间】:2017-02-09 05:44:21
【问题描述】:

抱歉,如果我发疯了,但如下图所示,我的网格内的每个 RowDefinition 似乎都在为其自身添加 '0.5'px 垂直边距。

这是一个完全空白的项目,从头开始创建。

是我记错了还是有什么问题?

<Grid UseLayoutRounding="True" SnapsToDevicePixels="True">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>
    <Border Grid.Row="0" Width="40" Height="10" Background="Aqua" Margin="1"/>
    <Border Grid.Row="1" Width="40" Height="10" Background="Red" Margin="1"/>
</Grid>

请注意,显示此内容的不仅仅是 Visual Studio 的设计器窗口,二进制文件也显示相同。

【问题讨论】:

  • 每个Border 元素上都有Margin="1"............
  • @Zack 是的,但是正在渲染1.5
  • 删除 UseLayoutRounding="True" 就好了。
  • @ChrisW。这对我没有任何作用......
  • @ChrisW。请在发布之前尝试您的建议...

标签: c# wpf xaml margin


【解决方案1】:

因此,如果您删除了 cmets 中提到的两个属性,这些属性在这种情况下允许根据测量/排列通道进行调整,您应该回到您想要的边距。

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>
    <Border Grid.Row="0" Width="40" Height="10" Background="Aqua" Margin="1"/>
    <Border Grid.Row="1" Width="40" Height="10" Background="Red" Margin="1"/>
</Grid>

希望这会有所帮助。

【讨论】:

  • @Clemens 嗯,我刚刚将它加载到一个新的项目中,所以我不确定会有什么不同?如果结果不正确,我当然会删除它。
猜你喜欢
  • 1970-01-01
  • 2013-09-05
  • 1970-01-01
  • 2015-03-17
  • 1970-01-01
  • 1970-01-01
  • 2020-01-04
  • 1970-01-01
  • 2017-06-04
相关资源
最近更新 更多