2010-06-20 2 views
7

나는 이런 식 ListView가 있습니다WPF ListView는 내부 레이아웃 패널 주위에 한 픽셀 테두리가 있습니다. 어떻게 제거합니까?

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

그것은 폭, 비어 내가 정의한 사용자 정의 패널의 높이 15 X 15 내가이 런타임에서의 실제 크기입니다 확인할 수있는 경우 . 그러나 ListView 자체의 크기는 17 x 17입니다. 즉, 패널과 ListView 사이에 한 픽셀 경계가 있습니다.

사용자 정의 패널에서 시작하고 트리를 걸어, 나는 다음과 같은 조상 얻을 :

  • ItemsPresenter :의 15x15
  • 에서 ScrollViewer :의 15x15
  • 그리드 :의 15x15
  • 에서 ScrollViewer를 :의 15x15
  • 테두리 : 17x17
  • ListView : 17x17

ListView의 채우기를 -1로 변경하면 테두리가 제거되지만 몇 가지 다른 문제가 발생합니다.

전체 ListView를 retempl하는 것을 피하려고합니다. 다른 모든 것은 잘 작동합니다. 스타일을 통해이 한 픽셀 경계를 제거 할 수있는 방법이 있습니까?

답변

2

ListView의 기본 템플릿을 실제로 보았습니다. 실제로 Border에는 1의 명시 적 패딩이 있습니다. 따라서 템플릿을 재정의하지 않고도 할 수 있다고 생각하지 않습니다. 어쨌든, 그다지 어렵지 않습니다. StyleSnooper 나 ShowMeTheTemplate 같은 도구를 사용하여 기본 템플릿을 복사하면됩니다 (Blend도 그렇게 할 수 있다고 생각합니다).

+0

유감스럽게도 .... 확인을 클릭합니다. :( –

+1

대신에 ListBox를 사용했지만 결국 체크 표시가 나타납니다.이 질문에서 경쟁은 치열했습니다 ...;) –

8

블렌드하면 정말 간단합니다. 목록 뷰를 마우스 오른쪽 단추로 클릭하고 템플릿을 편집하고 테두리에서 패딩을 제거하도록 선택할 수 있습니다. 이 작업은 xaml에서 직접 수행 할 수 있습니다. 모든 listview에이 경계선이 없기를 바란다면이 내용으로 프로젝트의 루트에 MyprojectnameResources.xaml이라는 리소스 파일을 만듭니다.

<ResourceDictionary 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
<ControlTemplate x:Key="ListViewNewTemplate" TargetType="{x:Type ListBox}"> 
    <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="0" SnapsToDevicePixels="True"> 
     <ScrollViewer Focusable="False" Padding="{TemplateBinding Padding}"> 
      <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
     </ScrollViewer> 
    </Border> 
    <ControlTemplate.Triggers> 
     <Trigger Property="IsEnabled" Value="False"> 
      <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> 
     </Trigger> 
     <Trigger Property="IsGrouping" Value="True"> 
      <Setter Property="ScrollViewer.CanContentScroll" Value="False"/> 
     </Trigger> 
    </ControlTemplate.Triggers> 
</ControlTemplate> 
<!-- Resource dictionary entries should be defined here. --> 

그런 다음 당신은 단순히 ("더러운"강조) 원하는 목록보기로

<ListView Width="1020" Height="764" ItemsSource="{Binding Destinations}" ItemTemplate="{DynamicResource DestinationDataTemplate}" Canvas.Top="0" Canvas.Left="0" BorderThickness="0" Template="{DynamicResource ListViewNewTemplate}" /> 
+0

국경에 바보 패딩 = "1"이었습니다. Padding = "0"으로 변경하면 해결책이되었습니다. – DaleyKD

5

신속하고 더러운 솔루션이 템플릿을 사용할 수 있습니다

<ListView Padding="-1" /> 
+0

고맙습니다! WinRT에서 완벽하게 작동합니다. –

3

가장 간단한 해결책은 Border의 두께를 0으로 설정하는 것입니다 :

<ListBox BorderThickness="0" /> 

필요하지 않음 템플릿 ...

관련 문제