ListView 中相同高度的像素大小不正确:如何强制像素 height/size

Incorrect pixel size for same height in ListView: how to enforce pixel height/size

我有一个 ListView 在 C# WPF 应用程序中承载用户控件的多个实例。

此用户控件显示始终具有相同大小“1”的水平线。

但是在屏幕上,应该具有相同高度的线显示为 +/-1 像素高度差!!!

问题:如何强制渲染将渲染具有相同 PIXEL 高度的线条?!

这里是用户控件中的Line定义:

用户控件的行定义:

<Rectangle Grid.Row         = "1"
           Grid.Column      = "0"
           Grid.ColumnSpan  = "2"
           Fill             = "DodgerBlue"
           Height           = "1"
           Margin           = "0, 1, 0, 2" />

和列表视图:

<ListView ItemsSource                   = "{Binding FoundBooks, Mode=OneWay}"
          SelectedItem                  = "{Binding SelectedBookPreview}"
          Grid.Row                      = "1" 
          Grid.Column                   = "0" 
          SelectionMode                 = "Single"
          HorizontalContentAlignment    = "Stretch">

    <ListView.ItemTemplate>
        <DataTemplate DataType="{x:Type vm:vmLessonBookPreview}">
            <ucont:ucLessonBookListViewItem DataContext         = "{Binding}"
                                            HorizontalAlignment = "Stretch" 
                                            Margin              = "-3, 0, -3, 0" />
        </DataTemplate>
    </ListView.ItemTemplate>

</ListView>

更多笔记;

看来真的是 ItemsControl 展示器的问题,会不会是一个错误?

好的,解决方案非常简单,虽然找到它比其他任何事情都更幸运...

我只需要将 UseLayoutRounding 添加到 Rectangle 控件中...:[=​​11=]

<Rectangle Grid.Row             = "1"
           Grid.Column          = "0"
           Grid.ColumnSpan      = "2"
           Fill                 = "DodgerBlue"
           UseLayoutRounding    = "True" 
           Height               = "1"
           Margin               = "0, 1, 0, 2" />

希望对其他人也有帮助!