如何使ItemsControl中的项目可滚动?

时间:2019-04-12 12:36:51

标签: wpf wpf-controls scrollviewer itemscontrol

我的项目中有一个ItemsControl,如果有多个无法容纳在视图中的项目,则应该可以滚动。我用ItemsControl包装了ScrollViewer,但它只显示了不起作用的滚动条。为什么自从我定义了ItemTemplate以来,默认情况下ItemControl的项就无法滚动。

这是我的XAML

                <Border Style="{StaticResource styleUpdatesContentBorder}">

                    <ItemsControl x:Name="updateDownloadStatus" ItemsSource="{Binding LatestUpdates}">
                           <ItemsControl.Template>
                                <ControlTemplate>
                                <ScrollViewer x:Name="ScrollViewer" Style="{StaticResource QSFScrollViewerStyle}" VerticalScrollBarVisibility="Auto" Padding="{TemplateBinding Padding}">
                                        <ItemsPresenter />
                                    </ScrollViewer>
                                </ControlTemplate>
                            </ItemsControl.Template>
                        <ItemsControl.ItemContainerStyle>
                            <Style>
                                <Setter Property="Control.Margin" Value="5"/>
                                <Style.Triggers>
                                    <Trigger Property="Control.IsMouseOver" Value="True">
                                        <Setter Property="Control.ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                                            Path=Content.FileName}"/>
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </ItemsControl.ItemContainerStyle>
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Vertical"/>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Border Background="#01FFFFFF" BorderBrush="DarkGray" BorderThickness="1" CornerRadius="3" >
                                    <Grid Margin="5,5,5,5">
                                    <Grid.RowDefinitions>
                                        <RowDefinition></RowDefinition>
                                        <RowDefinition></RowDefinition>
                                        <RowDefinition></RowDefinition>
                                        <RowDefinition></RowDefinition>
                                    </Grid.RowDefinitions>
                                        <TextBlock Grid.Row="0" Text="{Binding Activity}" Style="{StaticResource styleLatestProductUpdates}" />
                                        <TextBlock Grid.Row="1" Text="{Binding FileName}" Style="{StaticResource styleLatestProductUpdates}"/>
                                        <TextBlock Grid.Row="2" Text="{Binding Size}" Style="{StaticResource styleLatestProductUpdates}" />
                                    <telerik:RadProgressBar Name="downloadProgress" Grid.Row="3"
                                 HorizontalAlignment="Center"  Width="265"
                                Foreground="Goldenrod"  />
                                </Grid>
                                </Border>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                </Border>

当前输出:output

0 个答案:

没有答案