Bonjour tout le monde,
dans mon appli WPF actuel, j'ai une page contenant une ListBox de ce style :
lié au ObjectDataProvider suivant
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <ListBox x:Name="lbxCustomer" DataContext="{Binding Source={StaticResource odpCustomer}}" ItemsSource="{Binding}" ScrollViewer.VerticalScrollBarVisibility="Visible" > <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Label Content="{Binding Path=CustRef}" Width="100" HorizontalAlignment="Left" VerticalAlignment="Center" /> <Label Content="{Binding Path=CustState}" Width="100" HorizontalAlignment="Left" VerticalAlignment="Center" /> <Label Content="{Binding Path=CustReasons}" Width="350" HorizontalAlignment="Left" VerticalAlignment="Center" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
+ une petit classe Customer, implémentant ObservableCollection, permettant le Binding :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4<Page.Resources> <ObjectDataProvider x:Key="odpCustomer" /> </Page.Resources>
tout ceci marche très bien, à l'exception près que la méthode qui remplit la CustomerBindingList met environ 5 minutes à s'exécuter, temps pendant laquelle la fenêtre est bloqué. :-/
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 public class CustomerBinding { public string CustRef { get; set; } public string CustState { get; set; } public string CustReasons { get; set; } public class CustomerBindingList ObservableCollection<CustomerBinding> { } }
j'ai tenté plusieurs méthodes, dont celle ci, mais le résultat est souvent pire. (actuellement no seulement la pge se bloque mais en plus la liste n'apparait plus du tout, même après la fin du traitement.)
Voila le code actuel de ma page xaml.cs
le top, ce serait qu'au chargement de la page, la listbox des customers apparaissent progressivement, et que la page ne soit pas bloqué. Je ne sais même pas si c'est possible... (je sais que ça l'est en windows form cependant)
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
22
23
24
25
26
27
28
29
30
31 private CustomerBinding.CustomerBindingList lstCustomers; private delegate void AppelMethodeDelegate(); public pagCustomer() { InitializeComponent(); lstCustomers = new CustomerBinding.CustomerBindingList(); AppelMethodeDelegate appel = new AppelMethodeDelegate(GetCustomers); this.Dispatcher.BeginInvoke(appel, DispatcherPriority.Background, null); ObjectDataProvider odpCustomer = this.FindResource("odpCustomer") as ObjectDataProvider; if (odpCustomer != null) odpCustomer.ObjectInstance = lstCustomers; /*lstCustomers.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(lstCustomers_CollectionChanged);*/ } private void GetCustomers() { // du code pour remplir lstCustomers } private void lstCustomers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs a) { ObjectDataProvider odpCustomer = this.FindResource("odpCustomer") as ObjectDataProvider; if (odpCustomer != null) odpCustomer.ObjectInstance = lstCustomers; odpCustomer.Refresh(); }
Merci d'avance pour tout aide.
Partager