简体   繁体   中英

ScrollViewer not working with ItemsControl

I'm trying to use a ScrollViewer to be able to scroll the items in an ItemsControl but for some reason, it's not working. The scroll view shows but it is disabled.

<UserControl x:Class="Tool.Views.ShortcutsView"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            d:DesignWidth="500"
            mc:Ignorable="d" Height="541">

<UserControl.Resources>
    <Style x:Key="GlobalShortcutButtonTemplate" TargetType="{x:Type Button}"> 
     <!-- Style code -->
 </Style>

</UserControl.Resources>

        <Grid Margin="10,40,10,0" Background="White" Height="108" VerticalAlignment="Top">


            <ScrollViewer CanContentScroll="True">        
                <ItemsControl 
                        ItemsSource="{Binding ShortcutsObservableCollection}" 
                        Height="108" VerticalAlignment="Top" HorizontalAlignment="Left">

                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel Orientation="Horizontal" HorizontalAlignment="Center"  Margin="10"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>

                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Button 
                                    Height="35" 
                                    Content="{Binding ShortcutName}" 
                                    Command="{Binding ShortcutCommand}"
                                    CommandParameter="{Binding FilePath}" 
                                    Margin="10 0 0 10"
                                    Background="#FF30CCFF" 
                                    Foreground="White"
                                    Padding="10,0"/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>


        </Grid>
</UserControl>

This is what I see...

在此处输入图片说明

There are plenty of items in the ItemsControl for the scroller to show and be able to scroll the items in it, the rest of the items are hidden.

Any idea what can I do to make the scroller to show up properly?

Just remove Height="108" from your ItemsControl. You can't scroll because there is nothing to scroll.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM