This is my question:
I have 200,0000 Employee object(Id,Name,Job,Address) store at a database.
I read all Employee object to Empolyee[].
I create a window form application:
I create a WPF UserControl(inside ListBox),name is "wpfUserControl1".
I put "wpfUserControl1" into a window form.
I set wpfUserControl1.listBox.ItemsSource = Employee[].
Employee objects was displayed immediately.
// Performance is very good!
I create a WPF Application
I create a MainWindow object.
I put a ListBox to mainWindow.
I set listBox.ItemsSource = Employee[].
The speed of loading is very slow and occur outofmemeory exception.
// If i load 1000 objects, performance is too slow!
开发者_Python百科
My doubt is :
Why same WPF UserControl was Hosted into WinFormApp and WpfApp ,it's performance difference is so big?
Could it perhaps have something to do with virtualizing? For instance, the WPF datagrid has virtualizing turned on by default, but if you place the datagrid inside a stackpanel and don't provide any width/height restrictions, then you effectively nullify virtualization since the stackpanel allows the datagrid to grow infinitely thus having to create DataGridRows for hundreds of thousands items.
I'm just guessing that the same effect might be happening with your usercontrol. In WinForms the hosting control propbably provides specific width/height restrictions and doesn't allow the usercontrol to grow infinitely. In WPF on the other hand, depending on how your WpfApp's MainWindow is defined, the usercontrol might grow infinitely.
Try setting a specific width/height for your usercontrol or mainwindow and see if the performance gets better...
精彩评论