NOVINKA - Online rekvalifikační kurz Java programátor. Oblíbená a studenty ověřená rekvalifikace - nyní i online.
NOVINKA – Víkendový online kurz Software tester, který tě posune dál. Zjisti, jak na to!
Avatar
ORRNY99
Člen
Avatar
ORRNY99:25.6.2016 22:24

Ahoj lidi,
potřeboval bych trochu poradit. Mám ListView a v něm cca 1000 položek. Lze nějakým způsobem zajistit plynulé posouvání a zároveň zachovat virtualizaci. Vyzkoušel jsme několik různých způsobů například nastavení CanContentScroll = "False" což zpočátku fungovalo, ale aplikace pak pracovala velice pomalu. Našel jsem pár článku na toto téma. Jestli má někdo s tímto zkušenosti budu velice rád za jakoukoliv radu. Díky moc.

Zde je můj současný zdrojový Kód:

<Style x:Key="CommonListViewStyle" TargetType="{x:Type ListView}">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
            <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
            <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="AlternationCount" Value="2" />
            <Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True" />
            <Setter Property="VirtualizingStackPanel.VirtualizationMode" Value="Recycling" />
            <Setter Property="VirtualizingStackPanel.IsVirtualizingWhenGrouping" Value="True" />
            <Setter Property="SnapsToDevicePixels" Value="True"/>
            <Setter Property="UseLayoutRounding" Value="True"/>
            <Setter Property="Padding" Value="15,10,15,0"></Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListView}">
                        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                            <ScrollViewer Focusable="False">
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="{TemplateBinding Padding}"/>
                            </ScrollViewer>
                        </Border>
                        <ControlTemplate.Triggers>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsGrouping" Value="true"/>
                                    <Condition Property="VirtualizingStackPanel.IsVirtualizingWhenGrouping" Value="False"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="styleListViewItem" TargetType="{x:Type ListViewItem}">
            <Setter Property="OverridesDefaultStyle" Value="True"/>
            <Setter Property="SnapsToDevicePixels" Value="True"/>
            <Setter Property="UseLayoutRounding" Value="True"></Setter>
            <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Foreground" Value="{DynamicResource ItemsListViewForeground}"/>
            <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter>
            <Setter Property="Padding" Value="0,15,0,0"></Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListViewItem}">
                        <Grid x:Name="grid" Focusable="False">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Border x:Name="hover"
                                                        Background="{DynamicResource IsMouseOverItemsListView}"
                                                        BorderBrush="{x:Null}"
                                                        BorderThickness="0"
                                                        CornerRadius="0"
                                                                Height="24"
                                                        HorizontalAlignment="Stretch"
                                                        VerticalAlignment="Stretch"
                                                        Visibility="Collapsed"/>
                            <Border Grid.Row="0" x:Name="highlight"
                                    Height="24"
                                    Focusable="False"
                                                        Background="{DynamicResource IsSelectedItemsListViewAccentColor}"
                                                        BorderBrush="{x:Null}"
                                                        BorderThickness="0"
                                                        CornerRadius="0"
                                                        HorizontalAlignment="Stretch"
                                                        VerticalAlignment="Stretch"
                                                        Visibility="Collapsed"/>

                            <ContentPresenter Grid.Row="0" Content="{TemplateBinding Content}"
                                     ContentTemplate="{TemplateBinding ContentTemplate}"/>
                            <Border Height="0"

                                                        BorderBrush="#99D7D7D7"
                                                        BorderThickness="0,0,0,0"
                                                        Grid.Row="1"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="hover"
                                                                Property="Visibility"
                                                                Value="Visible"/>
                            </Trigger>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter TargetName="highlight"
                                                                Property="Visibility"
                                                                Value="Visible"/>
                                <Setter Property="Foreground" Value="White" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <ListView
           x:Name="ListViewData"
           ItemsSource="{Binding FirstSimplePlaylistFiles,Mode=OneWay}"
           Style="{StaticResource CommonListViewStyle}"
           behaviours:MultiSelectorBehaviours.SynchronizedSelectedItems="{Binding SelectedPlayListFiles, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
           SelectedItem="{Binding SelectedPlayListFile,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
           ItemContainerStyle="{DynamicResource styleListViewItem}"
           VirtualizingStackPanel.ScrollUnit="Pixel"
           VirtualizingStackPanel.CacheLength="2,3"
           VirtualizingStackPanel.CacheLengthUnit="Page"
           ScrollViewer.IsDeferredScrollingEnabled="True" >


            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel
                    Orientation="Vertical"
                    VirtualizingStackPanel.IsVirtualizing="True"
                    VirtualizingStackPanel.VirtualizationMode="Recycling"
                    ScrollViewer.IsDeferredScrollingEnabled="True"  />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>

            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
                            <Setter Property="Control.Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <StackPanel>
                                            <ContentPresenter Content="{TemplateBinding ContentControl.Content}"
                                            ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                                            ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" />
                                            <ItemsPresenter Margin="0,0,0,20" />
                                        </StackPanel>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate >
                            <Grid d:DesignWidth="462.5" Height="51">
                                <StackPanel>
                                   ......
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ListView.GroupStyle>

            <ListView.ItemTemplate>
                <DataTemplate>
                     ......
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
 
Odpovědět
25.6.2016 22:24
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 1 zpráv z 1.