【问题标题】:WPF Listbox border on right side blurryWPF Listbox 右侧边框模糊
【发布时间】:2016-06-08 16:47:40
【问题描述】:

我有一个带有显示一些数据的列表框的 WPF 应用程序。当我在窗口中心有列表框并且窗口宽度不均匀时,右侧的列表框是模糊的。 (绿色为矩形,蓝色部分为文本框) 我试图在几乎所有地方应用SnapsToDevicePixels,但没有结果。 (我知道它应该被子元素继承,但我差点把头发拉出来)

我可以通过将其设置为 HorizontalAlignment="Left" 来克服这个问题,并且 has 始终处于固定大小,但我知道我只是遗漏了一些东西,因为文本框确实被正确渲染了。

这是我的(尽可能干净的)代码,显示了行为:

<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>

【问题讨论】:

  • 尝试从 200 开始退出 ListBox 内容。

标签: c# wpf listbox snapstodevicepixels


【解决方案1】:

Window 上设置UseLayoutRounding="True"

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

【讨论】:

  • ......有时......我读到它基本上是一样的 - 显然不是。谢谢
猜你喜欢
  • 2015-12-17
  • 2022-11-16
  • 1970-01-01
  • 1970-01-01
  • 2020-09-17
  • 1970-01-01
  • 1970-01-01
  • 2015-03-26
  • 1970-01-01
相关资源
最近更新 更多