I have a WPF application in which I have a combobox
<ComboBox Margin="2,0,5,0" Width="178" ItemsSource="{Binding Animateur}" DisplayMemberPath="fsign_nom" SelectedIndex="0" >
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
the ItemsSource
contains 20100 items , the problem is when I try to open the combobox to select an element, the application were blocked .
the viewmodel class
_service.GetAnimateur((item, error) =>
{
if (error != null)
{
// TODO : traitement d'erreur
}
else
{
_Animateur.Clear();
item.ForEach(Elem =>
{
_Animateur.Add(Elem);
});
}
});
the Asynchrounous method :
public async void GetAnimateur(Action<List<fiche>, Exception> callback)
{
try
{
Task<List<fiche>> data = (Task<List<fiche>>)Task.Run(
() =>
{
DataEntities _db = new DataEntities();
_db.Configuration.LazyLoadingEnabled = false;
var dpcs = _db.fiche;
return new List<fiche>(dpcs);
});
var result = await data;
callback(result, null);
}
catch (Exception ex)
{
callback(null, ex);
}
}
I have seen this article so I added the virtualization part, but I got the same result.
So I need to know :
- How can I fix this problem?
- What is the max number of items in the
ItemsSource
?