使用ListBox.Template时ListBox内部丢失滚动查看器功能

时间:2016-02-17 16:21:18

标签: wpf

我想在下面的ListView中实现头文件,我是通过ListBox.Template实现的,但是通过这样做,我丢失了ListBox中的默认垂直滚动查看器。如何通过现有实现获得回报。感谢

<ListBox ItemsSource="{Binding HistoryDetails}" 
     MaxHeight="250"
     MinWidth="300"
     MinHeight="50"
     AlternationCount="2"
     Grid.IsSharedSizeScope="True">

<ListBox.Template>
    <ControlTemplate>
        <DockPanel LastChildFill="True">
            <Grid DockPanel.Dock="Top" Height="40">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="col1"></ColumnDefinition>
                    <ColumnDefinition SharedSizeGroup="col2"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="Action" Margin="10" FontWeight="Bold"></TextBlock>
                <TextBlock Grid.Column="1" Text="Description" Margin="10" MaxWidth="600" FontWeight="Bold"></TextBlock>
            </Grid>
            <ItemsPresenter></ItemsPresenter>
        </DockPanel>
    </ControlTemplate>
</ListBox.Template>
<ListBox.ItemTemplate>
    <DataTemplate>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition SharedSizeGroup="col1"></ColumnDefinition>
                <ColumnDefinition SharedSizeGroup="col2"></ColumnDefinition>
                <ColumnDefinition SharedSizeGroup="col3"></ColumnDefinition>
                <ColumnDefinition SharedSizeGroup="col4"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Column="0" Text="{Binding Note}" Margin="10"></TextBlock>
            <TextBlock Grid.Column="1" Text="{Binding Description}" Margin="10" TextWrapping="Wrap" MaxWidth="600"></TextBlock>
        </Grid>
    </DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

1 个答案:

答案 0 :(得分:0)

在您的模板中。把它放在你的ItemsPresenter周围:

<ScrollViewer 
    x:Name="ScrollViewer"
    Margin="0"
    BorderBrush="{x:Null}"
    BorderThickness="0"
    Padding="{TemplateBinding Padding}"
    ScrollViewer.HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
    ScrollViewer.VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
    Background="{TemplateBinding Background}">
    <ItemsPresenter/>
</ScrollViewer>

我希望这有帮助!