WPF内部集合虚拟化无法正常工作

时间:2015-07-20 16:33:35

标签: c# wpf ui-virtualization

我已经在WPF中实现了下面提到的代码,因为我已经实现了延迟加载的虚拟化,但是当我的内部集合有1000个记录时它不起作用,那么它将花费很多时间在屏幕上加载。

<ListBox x:Name="Mappingcontrol" Grid.Row="1"
                     DataContext="{Binding ElementName=Grids,Path=DataContext}"
                     VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                     ItemsSource="{Binding Path=MultiMappingCollectionList, Mode=TwoWay}"
                     VirtualizingStackPanel.IsVirtualizing="True" 
                     VirtualizingStackPanel.VirtualizationMode="Recycling"
                     BorderThickness="0" BorderBrush="Transparent"
                     Background="Transparent"
                     HorizontalContentAlignment="Stretch"
                     VerticalContentAlignment="Stretch"
                     ItemContainerStyle="{StaticResource TransparentListBoxStyle}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Border Padding="0,10,0,10" BorderThickness="0,0,0,1"
                                BorderBrush="{StaticResource Gray5SolidBrush}">
                            <Grid x:Name="Gridmain" Margin="4,0,0,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition x:Name="default" Width="0.5*" SharedSizeGroup="default" />
                                    <ColumnDefinition x:Name="atrioValue" Width="1*"
                                                      SharedSizeGroup="atrioValue" />
                                    <ColumnDefinition x:Name="externalValue" Width="2*"
                                                      SharedSizeGroup="externalValue" />
                                </Grid.ColumnDefinitions>

                                <ToggleButton VerticalAlignment="Top"
                                              HorizontalAlignment="Left"
                                              Style="{DynamicResource ToggleButtonStyle}"
                                              Margin="30,12,10,10" IsTabStop="False" Width="25"
                                              Height="25"
                                              IsChecked="{Binding IsDefault, Mode=TwoWay}">

                                <TextBlock Grid.Column="1" Margin="0,15,10,10" HorizontalAlignment="Left"
                                           VerticalAlignment="Top"
                                           Text="{Binding Path=Description}"
                                           Style="{StaticResource ContentDataText}"
                                           Name="txtDescription" />

                                <ListBox x:Name="GroupListBox" Grid.Column="2"
                                         ItemsSource="{Binding Path=MultiMapping,Mode=TwoWay}"
                                         HorizontalContentAlignment="Stretch"
                                         BorderThickness="0"
                                         BorderBrush="Transparent"
                                         Background="Transparent"
                                         VerticalContentAlignment="Stretch"
                                         VirtualizingStackPanel.IsVirtualizing="True"
                                         VirtualizingStackPanel.VirtualizationMode="Recycling"
                                         VirtualizingStackPanel.CacheLength="2,3"
                                         VirtualizingStackPanel.CacheLengthUnit="Page"
                                         ItemContainerStyle="{StaticResource TransparentListBoxStyle}">

                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal" CanVerticallyScroll="True" Height="200">
                                                <telerik:RadWatermarkTextBox x:Name="ExternalValueTextBox"
                                                                             HorizontalAlignment="Left"
                                                                             TabIndex="100"
                                                                             KeyboardNavigation.TabIndex="100"
                                                                             IsTabStop="True"
                                                                             Width="250"
                                                                             MaxLength="35"
                                                                             TextWrapping="Wrap"
                                                                             Validation.ErrorTemplate="{DynamicResource CustomErrorTemplate}"
                                                                             Text="{Binding Path=ExternalValue, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                                                                             PreviewTextInput="ExternalValueTextBox_OnPreviewTextInput"
                                                                             Style="{DynamicResource RadWatermarkTextBoxDefault}"
                                                                             Visibility="{Binding Path=ExternalValue,Converter={StaticResource StarVisibilityConverter}}"
                                                                             Margin="0,5,0,0">

                                                </telerik:RadWatermarkTextBox>

                                                <Button x:Name="DeleteButton" Background="Transparent"
                                                        BorderThickness="0"
                                                        BorderBrush="Transparent"
                                                        CommandParameter="{Binding}"
                                                        Command="{Binding DataContext.RemoveGrouplistCommand,  RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                                                        HorizontalAlignment="Right"
                                                        VerticalAlignment="Center"
                                                        Visibility="{Binding Path=RemoveButtonVisibility,Converter={StaticResource BooleanHiddenVisibleConverter},Mode=TwoWay}"
                                                        Margin="15,5,15,0"
                                                        Style="{DynamicResource ButtonInvisibleNoColorEffects}">
                                                    <Button.Content>
                                                        <Rectangle Style="{StaticResource SmallCloseIcon}" />
                                                    </Button.Content>
                                                </Button>

                                                <Grid x:Name="AddGrid"
                                                      Visibility="{Binding Path=AddbuttonVisibility,Converter={StaticResource BooleanVisibilityConverter}}">

                                                    <controls:ActionImageButton x:Name="AddButton"
                                                                                Content="Add Another"
                                                                                DataContext="{Binding ElementName=Root,Path=DataContext}"
                                                                                CommandParameter="{Binding ElementName=txtDescription,Path=Text}"
                                                                                Command="{Binding AddGrouplistCommand}"
                                                                                HorizontalAlignment="Right"
                                                                                VerticalAlignment="Center"
                                                                                IsEnabled="{Binding ElementName=ExternalValueTextBox,Path=Text,Converter={StaticResource StarVisibilityConverter},ConverterParameter=CanAdd}"
                                                                                Margin="5,5,30,5"
                                                                                Style="{StaticResource ActionImageButtonMedium}" />
                                                </Grid>
                                            </StackPanel>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>

                            </Grid>
                        </Border>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

如果有人可以向我说明我做错了什么,那将是非常有帮助的 提前谢谢。

0 个答案:

没有答案