views:

23

answers:

1

I have a ListView that goes something like this:

<ListView 
    x:Name="SeriesListView"
    SnapsToDevicePixels="True"
    ItemsSource="{Binding Items}"
    BorderBrush="Transparent" BorderThickness="0"
    Padding="0" Margin="0" 
    VerticalContentAlignment="Top"
    Background="Purple"
    LostFocus="ListView_LostFocus"
    >

    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <local:LDSeriesPanel
                SnapsToDevicePixels="True" 
                MaxWidth="{Binding ElementName=itControl,Path=ActualWidth}"
                VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 
                MinHeight="{x:Static local:LDSeriesPanel.MIN_HEIGHT}" 
                MinWidth="{x:Static local:LDSeriesPanel.MIN_WIDTH}"
                Margin="0"
                Background="Aquamarine"/>
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>

When it's empty, the Width and Height of the custom panel I've defined is 15 x 15. I can confirm these are the actual dimensions at runtime. However, the ListView itself has dimensions of 17 x 17 (that is, a one pixel border between the panel and the ListView).

Starting from the custom panel and walking up the tree, I get the following ancestors:

  • ItemsPresenter: 15x15
  • ScrollViewer: 15x15
  • Grid: 15x15
  • ScrollViewer: 15x15
  • Border: 17x17
  • ListView: 17x17

If I change the Padding on the ListView to -1, it removes the border but causes several other issues.

I'm hoping to avoid retemplating the entire ListView. Everything else is working fine. Is there some way I can Remove this one pixel border, perhaps through a style?

A: 

I just had a look at the default template for ListView, indeed the Border has an explicit padding of 1... so I don't think you can do it without redefining the template. Anyway, it's not very difficult : just copy the default template using a tool like StyleSnooper or ShowMeTheTemplate (I think Blend can do it too), and change what you need...

Thomas Levesque
Grrr.... ok. :(
Scott Whitlock
I ended up using a ListBox instead, but I'll give you the checkmark. The competition was fierce on this question... ;)
Scott Whitlock