Bonjour à tous
Je suis en cours de développement d'une appliation C#
Dans mon fichier XAML, j'ai un ItemsControl avec ma liste bindée en ItemsSource. Par exemple :
Ensuite dans la partie behind de mon code je rempli une liste :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 <ItemsControl x:Name="lvDataBinding" Foreground="AliceBlue" ItemsSource="{Binding LstAvis}" Margin="0" ScrollViewer.CanContentScroll="True" VirtualizingPanel.IsVirtualizing="True" VerticalAlignment="Top"> <ItemsControl.ItemTemplate> <DataTemplate> <Border BorderBrush="White" BorderThickness="1" CornerRadius="3" Margin="{Binding strMargin}" Opacity="{Binding dblOpacityCurrent}" HorizontalAlignment="Left" VerticalAlignment="Top"> <Grid Width="{Binding dblWidth}" Height="{Binding strHeightGrid}" Tag="{Binding strNumAvis}" Margin="0.1" Background="{Binding scbColorCurrentSelected}" > </Grid> </Border> </DataTemplate> </ItemsControl.ItemTemplate> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <UniformGrid Columns="1"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl>
Seulement, mon application a besoin de 5 secondes pour exécuter la ligne suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 public void NewConstruct_View() { Application.Current.Dispatcher.Invoke(new Action(() => _lstAvistemp.Clear())); Dispatcher.Invoke(new Action(() => Mouse.OverrideCursor = Cursors.Wait)); //Insere la liste dans l'objet qui permettra son affichage for (int i = 0; i <= dt_DATA.Rows.Count - 1; i++) { Avis = new CL_Avis(); Avis.strNumAvis = dt_DATA.Rows[i]["QMNUM"].ToString(); Application.Current.Dispatcher.Invoke(new Action(() => _lstAvistemp.Add(Avis))); } Dispatcher.Invoke(new Action(() => LstAvis.ReplaceRange(_lstAvistemp))); Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.ContextIdle, null); }
et afficher ma grille à l'écran.
Code : Sélectionner tout - Visualiser dans une fenêtre à part Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.ContextIdle, null);
J'ai seulement 500 lignes, et je trouve que c'est lent pour 500 lignes. Qu'en dites-vous ?
Pour info le code ci-dessus est simplifié pour la lecture en réalité la grille est un peu plus complexe et je remplis une 20ène de champs dans ma liste dans le code behind.
Je travaille dans un thread et ma liste est de type RangeObservableCollection.
J'ai déjà corrigé les exceptions que j'avais :
J'avais dans ma liste une variable de visibilité bindée dans mon XAML qui était à null, maintenant je la remplis à "Hidden" et c'est ok, plus d'exceptions.System.Windows.Data Error: 23 : Cannot convert '<null>' from type '<null>' to type 'System.Windows.Visibility' for 'en-US' culture with default conversions; consider using Converter property of Binding. NotSupportedException:'System.NotSupportedException: Conversion de EnumConverter impossible à partir de (null).
à System.ComponentModel.TypeConverter.GetConvertFromException(Object value)
à System.ComponentModel.TypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
à System.ComponentModel.EnumConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
à MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)'
Comment améliorer les perfs ?
Merci.
Salutations
Partager