I was just wondering about something. I have a frame that loads pages and currently each page has a Page_Loaded
method that will run each time the page is accessed
As you point out the Page_Loaded
event will be fired each time the page is refreshed, so if you want the code to only be executed the once, then putting it in the constructor is the logical place.
Depending on how much code you need you might want to consider refactoring it into another method - but that's purely a matter of personal taste (or perhaps following coding standards).
UPDATE
I would guess that as the query used to generate tehBuildings
is returning null (stating the obvious) then there's some other code you need to call before calling getBuildings
. Without seeing your original code I wouldn't like to say what's now missing.
It's legitimate to do something in the constructor. I think this is fine.
WPF isn't quite like ASP.NET in terms of accessibility of objects / etc. It's a bit looser and so doing something in a constructor isn't quote the no-no it is in ASP.NET.