Separator in ItemsControl renders in different shades for each item

*爱你&永不变心* 提交于 2020-01-03 02:19:06

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!