WPF ListView滚动条滚动所有内容

时间:2013-12-10 19:50:15

标签: wpf listview scrollbar

我有以下ListView布局:

                <ScrollViewer HorizontalScrollBarVisibility="Visible">
                    <ListView Height="Auto" Name="lstvItems" Width="Auto" Background="#FF354D55" SelectionMode="Single" >
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Name:" DisplayMemberBinding="{Binding Name}" Width="100" />
                                <GridViewColumn Header="Type:" DisplayMemberBinding="{Binding Type}" Width="70" />
                            </GridView>
                        </ListView.View>
                    </ListView>
                </ScrollViewer>

如果我向ListView添加边框并且滚动条可用,则边框会与内容一起滚动。

如何阻止这种情况发生?

1 个答案:

答案 0 :(得分:1)

删除ScrollViewer

Default ListView Template已有ScrollViewer

从Expression Blend获得:

<ControlTemplate TargetType="{x:Type ListView}">
    <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="1" SnapsToDevicePixels="true">
        <ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}">
            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
        </ScrollViewer>
    </Border>
    <!-- more content here -->
</ControlTemplate>