WPF列表框右侧边框模糊。

3
我有一个 WPF 应用程序,其中有一个 ListBox 显示一些数据。当我将 ListBox 放在窗口中心并且窗口宽度不均匀时,右侧的 ListBox 会变得模糊。(绿色是矩形,蓝色部分是文本框) the (green) listbox has a blurry right side 我尝试在几乎所有地方应用 SnapsToDevicePixels,但没有结果。(我知道它应该被子元素继承,但我几乎要抓狂了)
我可以通过将其设置为 HorizontalAlignment="Left" 并始终使用固定大小来克服这个问题,但我知道我只是忽略了什么,因为文本框确实被正确呈现。
这是我的(尽可能干净的)代码,显示了这种行为:
<Window x:Class="WpfApplication2.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1"  
    Height="200" 
    Width="401px"  
    Background="Red" 
    SnapsToDevicePixels="True">
<Grid>
    <Rectangle Width="200" Height="50"  Fill="Blue" VerticalAlignment="Top" />
    <ListBox Height="94" VerticalAlignment="Bottom"  Width="200px" >
        <ListBoxItem>1</ListBoxItem>
        <ListBox.Template>
            <ControlTemplate TargetType="ListBox">
                <ScrollViewer Margin="0" Padding="0" SnapsToDevicePixels="True">
                    <StackPanel Margin="0" IsItemsHost="True" Width="200" Background="GreenYellow"/>
                </ScrollViewer>
            </ControlTemplate>
        </ListBox.Template>
        <ListBox.ItemContainerStyle>
            <Style TargetType="{x:Type ListBoxItem}">
                <Setter Property="SnapsToDevicePixels" Value="True"/>
                <Setter Property="Width" Value="200"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListBoxItem">
                            <Grid Background="Green" Height="40" SnapsToDevicePixels="True">
                                <ContentPresenter SnapsToDevicePixels="True"/>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ListBox.ItemContainerStyle>
    </ListBox>
</Grid>
</Window>

尝试将ListBox内容减少到200。 - paparazzo
1个回答

3

Window上的UseLayoutRounding="True"设置为真。

我还建议设置TextOptions.TextFormattingMode="Display"来提高文本清晰度。


有时候我读到它们基本上是一样的东西 - 显然不是这样。谢谢。 - user1515791

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接