简体   繁体   中英

wpf listview itempanel scrollviewer

When I set ListView.ItemsPanel in WrapPanel then right scrollbar is lost (not visible). And the content is scrolled by a mouse wheel and of course with the study of the visual tree in this scrollviewer all properties is installed correctly. What could be wrong here and why he is not visible.

        <Style TargetType="{x:Type ListView}">
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <WrapPanel Background="Transparent" MouseDown="WrapPanel_MouseDown_1" 
                             IsItemsHost="True"
                             Width="{Binding Path=ActualWidth,  RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollContentPresenter}}}">

                        </WrapPanel>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Path Fill="{Binding ElementName=tBlock, Path=Foreground}" Width="20" Height="20" Margin="5, 0, 0, 0" Stretch="Uniform" Data="{Binding SmallIcon}" />
                            <TextBlock Margin="5, 4, 5, 0" x:Name="tBlock" Grid.Column="1" TextWrapping="Wrap" Width="200" Text="{Binding Name}"></TextBlock>
                        </Grid>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>

This is the screenshot:

截图

set VerticalScrollBarVisibility and/or HorizontalScrollBarVisibility to the desired value:

<ListView
          ScrollViewer.HorizontalScrollBarVisibility="Visible" 
          ScrollViewer.VerticalScrollBarVisibility="Visible"> 
    <ListView.Style>
        <Style TargetType="{x:Type ListView}">
         // ...

VerticalScrollBarVisibility is Auto by default and I could not replicate your problem. However, I hope this helps.

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