I have an ItemsControl presenting TextBlocks, with a Separator at the bottom of each item.
My problem is that each Separator is rendered in a slightly different shade of gray - it looks really dodgy:
Here is my XAML:
<ItemsControl ItemsSource="{Binding Path=Items}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding}" ></TextBlock>
<Separator></Separator>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I have also tried using a thin border instead of the Separator, with the same result.
How can I make each line identical?
Try SnapsToDevicePixels="True"
<ItemsControl ItemsSource="{Binding Path=Items}" SnapsToDevicePixels="True">
If this doesn't help you can also try with
UseLayoutRounding="True"
(WPF 4)RenderOptions.EdgeMode="Aliased"
(Turn of anti-aliasing)
来源:https://stackoverflow.com/questions/5255071/separator-in-itemscontrol-renders-in-different-shades-for-each-item