I have a ListView
in my window. The ListView
's default ItemsPanel
was replaced with WrapPanel
. I also have a DataTemplate
for it's ListViewItem
s. In Runtime, main window will not responding for some time because the ListView
have more than 700 (and keep increasing) ListViewItem
s (from data binding). Is there a way to keep the main window responsive?
OPTIONAL: When the ListView
is not ready, i want a text (or ProgressBar
if possible) show up over the ListView
and saying something like "Please Wait..." or maybe "Loading Items...".
XAML:
<ListView x:Name="MyListView" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" HorizontalAlignment="Left" Height="577" VerticalAlignment="Top" Width="902" ScrollViewer.HorizontalScrollBarVisibility="Auto" Foreground="Black" Margin="10,10,0,0" ScrollViewer.CanContentScroll="True" BorderBrush="#FFC54B4B" BorderThickness="3" Background="White">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel MaxWidth="{Binding (FrameworkElement.ActualWidth),
RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
ItemWidth="{Binding (ListView.View).ItemWidth,
RelativeSource={RelativeSource AncestorType=ListView}}"
MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}"
ItemHeight="{Binding (ListView.View).ItemHeight,
RelativeSource={RelativeSource AncestorType=ListView}}" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
EDIT:
I tried this:
List<something> MyList = new List<something>();
ThreadPool.QueueUserWorkItem(_ =>
{
( Create MyList here...)
Dispatcher.BeginInvoke(new Action(() =>
{
MyListView.ItemsSource = MyList;
}));
});
Main window is still not responding until the ListView ready.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…