1

I'm trying to bind a big collection in MainViewModel as follows (example: clients{fullname, saleorders, ...}) :

internal Class MainViewModel : ViewModelBase{

private ObservableCollection<Client> _clients;
public ObservableCollection<clients> Clients
{
   get{ return _clients;}
   set
{ 
    _clients = value;
    RaisePropertyChanged("Clients");
}
}

}

Then in the XAML code, I have a ListView with modified itemTemplate and PanelTemplate. I made a card for each client (as a control).

<ListView ItemsSource="{Binding Clients, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
...
</ListView>

The problem is that my UI does not appear until the full client's card is loaded. This operation takes a long time, but I want to see the loading operation card by card at realtime. What I should do? Please help me, thanks.

Tony
  • 2,658
  • 2
  • 31
  • 46
Henka Programmer
  • 433
  • 6
  • 18
  • look into [virtualization](http://stackoverflow.com/questions/14456075/how-to-enable-ui-virtualization-in-standard-wpf-listview) – har07 Mar 02 '14 at 02:56
  • @har07 yes i did but the virtualization causes me a slow scrolling and so slow not normal. cause the client card containing list of saleorders, list of services that he/she consuming .... – Henka Programmer Mar 02 '14 at 03:02
  • Question: 1) is your _clients field populated on background that? (make sure you do that) 2) Why is our binding "TwoWay", don't think you would want that. – Manish Basantani Mar 02 '14 at 09:02
  • @Amby did u mean by populated on background worker? – Henka Programmer Mar 02 '14 at 13:37
  • By bgworker I essentially mean a non-UI thread. If you are filling _clients on default (UI) thread then it will freeze your UI at startup/loading. – Manish Basantani Mar 02 '14 at 18:56
  • Oh, thanks, but i load the full clients list firstly than i load the mainwindow as follow: 'load_clients(); App.Run(new mainwindow())' so the problem is in the binding i think that :) – Henka Programmer Mar 02 '14 at 19:30

1 Answers1

0

WPF does magic but not miracles!

I would suggest the following:

  1. Avoid code behind as much as possible (Zero if possible)
  2. Make use of Styles and Templates
  3. UpdateSourceTrigger=PropertyChanged is slower than UpdateSourceTrigger=Explicit
  4. Textblock is faster than TextBox, and Panels are different too so try changing some of them to increase the performance, you may want to make the heavier controls appear only when MouseOver or something like that.
  5. If you can't predict the approximate number of items, limit it by implementing simple next/previous page buttons.
  6. Make use of Virtualization. And do it correctly or don't do it at all.
  7. Make use of BackgroundWorker's ProgressChanged event
  8. Load collections inside collections with a delay or on a specific event.
Community
  • 1
  • 1
Bizhan
  • 16,157
  • 9
  • 63
  • 101
  • Question:) Did u mean by 'code behind' about the code behind the cards, control card events? – Henka Programmer Mar 02 '14 at 13:52
  • Code behind in general is any file which name ends with xaml.cs and refers to events, calling controls by their x:Name, creating or modifying visual elements or styles etc in code, and sometimes Converters. They all seem to break the WPF automatic optimizations or so – Bizhan Mar 02 '14 at 20:27