Hi all,
I develop an application C# WPF.
In my XAML i have an ItemsControl with my List in ItemsSource, in binding. For example :
<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>
Then in my behind code i have a function in a thread to fill a list :
public void NewConstruct_View()
{
Application.Current.Dispatcher.Invoke(new Action(() => _lstAvistemp.Clear()));
Dispatcher.Invoke(new Action(() => Mouse.OverrideCursor = Cursors.Wait));
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);
}
But my application need 5 seconds to execute
Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.ContextIdle, null);
and display my grid.
I have only 500 rows, i think it's very slow.
I simplified the code for reading, but i have only about 20 fields (it's not a lot...)
I worked in a thread, my list in a list of type RangeOBservableCollection.
Thank you for your help.
What I have tried:
I saw i have had some exceptions :
Quote:
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)'
I corrected this exception. I had a variable for visibility in my binding null, i filled this variable. It's ok.