WPF。按项目滚动ListBox

时间:2015-08-18 07:53:59

标签: wpf scroll listbox

我有列表框哪里有图标,我必须按项目滚动此列表框(现在它按像素滚动)#。我尝试使用ScrollViewer.CanContentScroll但它不起作用。我认为这是WrapPanel的问题

ListBox示例:

enter image description here

我的xaml:

     <Style TargetType="ListBox">
                <Setter Property="Height" Value="490"/>
                <Setter Property="Width" Value="968"/>
                <Setter Property="Margin" Value="30,98,362,135"/>
                <Setter Property="Padding" Value="5,25,0,27"></Setter>
                <Setter Property="VerticalAlignment" Value="Top"/>
                <Setter Property="HorizontalAlignment" Value="Left"/>
                <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Visible"/>
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                        <WrapPanel IsItemsHost="True" />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        <Style TargetType="ListBoxItem">
            <Setter Property="BorderThickness" Value="5"/>
            <Setter Property="BorderBrush" Value="Black"/>
            <Setter Property="Margin" Value="3,3,0,0"/> 
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border x:Name="backgroundBorder" Width="Auto">
                            <ContentPresenter>
                                <ContentPresenter.ContentTemplate>
                                    <DataTemplate>
                                            <Grid Width="170" Height="212" Background="Transparent">
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="auto" />
                                                    <RowDefinition Height="auto" />
                                                </Grid.RowDefinitions>
                                                <Image Grid.Row="0" Source="{Binding Path=Image}" Stretch="UniformToFill" />
                                                <Label Grid.Row="1" Margin="0,14,0,0"  Content="{Binding Path=Title}" HorizontalAlignment="Center" 
                                                   FontFamily="Arial" FontSize="18" FontWeight="Normal" Foreground="#3F3E3E"/>
                                            </Grid>
                                    </DataTemplate>
                                </ContentPresenter.ContentTemplate>
                            </ContentPresenter>
                        </Border>
 </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
<ListBox  ItemsSource="{Binding Path=MyImages, ElementName=window1}"
                     ScrollViewer.CanContentScroll="True" 
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                     ScrollViewer.VerticalScrollBarVisibility="Visible"/>

0 个答案:

没有答案