WPF右侧模糊列表框边框
问题描述:
我有一个WPF应用程序,显示一些数据的列表框。当我在窗口中心的列表框和窗口宽度不均匀时,在右侧列表框是模糊的。 (绿色是矩形,蓝色部分是文本框) 我试图几乎在任何地方都应用
SnapsToDevicePixels
而没有结果。 (我知道它应该由子元素继承,但即时通讯几乎把我的头发拉出来)WPF右侧模糊列表框边框
我可以通过将它设置为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>
答
在Window
集UseLayoutRounding="True"
。
我还建议设置TextOptions.TextFormattingMode="Display"
以提高文字清晰度。
+0
...有时...我读它基本上是同一件事 - 显然它不是。谢谢 – user1515791
尝试从200列表框内容退后。 – Paparazzi