Luca Petrini
Luca Petrini

Reputation: 1745

WPF page background loading...how to?

I have a WPF Window with tab control. Every tabitem of tab control have a frame with PAGE as content...like this:

 <TabItem Name="Tab01">
   <Frame Name="Tab01Frame" />
 </TabItem>
 MyPage Tab01Page = New MyPage()
 Tab01Frame.Navigate(Tab01Page)

Now, I have this problem. Every page for tabitem is loading on window contructor and this cause a performance bottleneck for window. It takes some seconds to show.

Is there a way to load pages on background process?

Upvotes: 2

Views: 1456

Answers (1)

Mark K
Mark K

Reputation: 121

To start, move the initialization code to the Loaded event (not in the constructor). This will make the UI appear more responsive. Also, use the Dispatcher object to background the task.

 private delegate void DelegateTypeYouDeclare();

 this.Dispatcher.BeginInvoke(new DelegateTypeYouDeclare(MethodToCall), null);

Those are just first steps. For a better example see the following MSDN article: http://msdn.microsoft.com/en-us/magazine/cc163328.aspx

Upvotes: 2

Related Questions