Charl
Charl

Reputation: 154

XAML Page constructor

I have a Silverlight 4 application.

What would cause the Constructor in my codebehind file to be called more than once?

Currently I suspect it gets called when I set the datacontext or do applytemplate.

I can see it when I debug the application and I put a breakpoint on the first line in my constructor, BUT it does not give me a stacktrace.

Thanks

Upvotes: 2

Views: 348

Answers (2)

David Wendelken
David Wendelken

Reputation: 11

I discovered that the MainPage.xaml.cs file can have a {usercontroname}_Loaded event.

I moved my method call that started the database query to that event instead of the constructor.

Works like a charm now.

Upvotes: 1

alexander.biskop
alexander.biskop

Reputation: 1862

the constructor should only be called once per control instance. Is your control maybe used more than once in your app? Or maybe a page that includes the control is instantiated more than once?

Cheers, Alex

Upvotes: 0

Related Questions