ScrollViewer не работает с ItemsControl - PullRequest
0 голосов
/ 13 октября 2018

Я пытаюсь использовать ScrollViewer, чтобы иметь возможность прокручивать элементы в ItemsControl, но по какой-то причине это не работает.Представление прокрутки показывает, но это отключено.

<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>

Это то, что я вижу ...

enter image description here

В ItemsControl есть множество предметов дляскроллер, чтобы показать и иметь возможность прокручивать элементы в нем, остальные элементы скрыты.

Любая идея, что я могу сделать, чтобы скроллер правильно отображался?

1 Ответ

0 голосов
/ 13 октября 2018

Просто удалите Height = "108" из вашего ItemsControl.Вы не можете прокручивать, потому что нечего прокручивать.

...