列表框未显示垂直滚动条WPF

时间:2017-03-17 18:29:39

标签: 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>

垂直滚动条未显示。

1 个答案:

答案 0 :(得分:1)

如果ControlTemplate实际上包含ScrollViewer,ScrollViewer.VerticalScrollBarVisibility只会产生影响:

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