2017-03-17 111 views
0

我有一个自定义列表框。但不显示滚动条。列表框不显示垂直滚动条WPF

<Style x:Key="noStyleToListboxItem" TargetType="{x:Type ListBox}"> 
     <Setter Property="SnapsToDevicePixels" Value="True"/> 
     <Setter Property="OverridesDefaultStyle" Value="True"/> 
     <Setter Property="BorderBrush" Value="Black"></Setter> 
     <Setter Property="BorderThickness" Value="2"></Setter> 
     <Setter Property="FocusVisualStyle" Value="{x:Null}"/> 
     <Setter Property="ScrollViewer.CanContentScroll" Value="True"></Setter> 
     <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"></Setter> 
     <Setter Property="VirtualizingPanel.ScrollUnit" Value="Pixel"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type ListBox}"> 
        <Border> 
         <ContentPresenter/> 
        </Border> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

垂直滚动条未显示。

+0

变化'VerticalScrollBarVisibility'到TRUE;或不管它被称为在'ListBox' ....和类型是怪异因为它是'ListBoxItem'的代码 – FCin

回答

1

ScrollViewer.VerticalScrollBarVisibility只有在ControlTemplate中实际上包含了ScrollViewer中有一个效果:

<Setter Property="Template"> 
    <Setter.Value> 
     <ControlTemplate TargetType="{x:Type ListBox}"> 
      <Border> 
       <ScrollViewer> 
        <ItemsPresenter/> 
       </ScrollViewer> 
      </Border> 
     </ControlTemplate> 
    </Setter.Value> 
</Setter>