0

我有一个列表框,我将大约 1000 个用户控件与 itemspaneltemplate 作为网格绑定到该列表框,并且我通过指定工作正常的行和列来放置每个用户控件。但问题是加载需要太多时间我什至使用了后台工作进程但也没有用。请帮助我解决上述问题的方法是什么。


<ListBox VerticalAlignment="Top" ItemsSource="{Binding Session.LstPlannedLightChkEntity,ElementName=uc, IsAsync=True}"  Grid.Row="0" 
                               VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"
                              local:DragDropHelper.IsDragSource="true" local:DragDropHelper.IsDropTarget="true" 
                              local:DragDropHelper.DragDropTemplate="{StaticResource planetTemplateDrag}"  
                              ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                              ScrollViewer.CanContentScroll="True"  
                            >
  <ListBox.ItemContainerStyle>
    <Style TargetType="ListBoxItem">
      <Setter Property="Grid.Row" Value="{Binding Row}"/>
      <Setter Property="Grid.Column" Value="{Binding Column}"/>
      <Setter Property="Grid.ColumnSpan" Value="{Binding ColumnSpan}" />
    <Style.Resources>
    <!-- Background of selected item when focussed -->
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
    <!-- Background of selected item when not focussed -->
    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
      </Style.Resources>
    </Style>
  </ListBox.ItemContainerStyle>
  <ListBox.ItemsPanel>
    <ItemsPanelTemplate>
      <local:GridControl x:Name="gcMenuPlanned" VerticalAlignment="Stretch"  Margin="-1,-1,0,0"
         ShowCustomGridLines="True" GridLineBrush="#FFE4E7EB" GridLineThickness="0.5" SnapsToDevicePixels="True">
        <local:GridControl.ContextMenu>
        <ContextMenu >
          <MenuItem Foreground="Black"  Header="Add Task" Click="AddTask_Click" Tag="{Binding CheckType}"  />
          <MenuItem Foreground="Black"  Header="Goto..."  Click="miGoto_Click" Tag="{Binding CheckType}"  />
        </ContextMenu>
      </local:GridControl.ContextMenu>
    </local:GridControl>
  </ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
  <DataTemplate>
    <local:LightFCCheckBlockControl  CheckColor="#FFA2CAEB" MouseLeftButtonDown="LightFCCheckBlockControl_MouseLeftButtonDown">
      <local:LightFCCheckBlockControl.ContextMenu>
        <ContextMenu >
          <MenuItem Foreground="Black"  Header="Edit" Click="miEdit_Click" Tag="{Binding CheckType}" Visibility="{Binding Path=OpacityForCCheck,Converter={StaticResource opacityToVisibility}}"/>
          <MenuItem Foreground="Black" Style="{StaticResource MenuItemBindingStyle }"  Click="miFreeze_Click" Tag="{Binding CheckType}" Visibility="{Binding Path=OpacityForCCheck,Converter={StaticResource opacityToVisibility}}">
          </MenuItem>
          <MenuItem Foreground="Black" Click="RemoveChecks_Click"  Header="Remove Checks" Tag="{Binding CheckType}"/>
          <MenuItem Foreground="Black" Click="DeleteChecks_Click"  Header="Delete Checks" Tag="{Binding CheckType}" Visibility="{Binding Path=OpacityForCCheck,Converter={StaticResource opacityToVisibility}}"/>
          <MenuItem Foreground="Black"  Header="Goto..."  Click="miGoto_Click" Tag="{Binding CheckType}" Visibility="{Binding Path=OpacityForCCheck,Converter={StaticResource opacityToVisibility}}"/>
        </ContextMenu>
      </local:LightFCCheckBlockControl.ContextMenu>
    </local:LightFCCheckBlockControl>
  </DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

谢谢Yogaraj我

4

1 回答 1

0

嗯,听起来有点奇怪。首先,你应该回答这个问题......真的有必要将1000个项目绑定到一个列表中,它应该在UI中显示吗?可用性不会是最好的。也许您可以选择延迟加载的方法。

其次,您是否禁用VirtualizationListBox? 通常,只渲染元素的视觉效果,这些视觉效果是可见的。在滚动的情况下,控件将被重用。

于 2013-01-21T13:11:22.097 回答