문제

In a WPF Window Application, I can override OnStartup method to add my own logic when the app is launched.

My my app is a add-on of another app, actually, its a UserControl.
Where to add my own logic to the app when the app is launched?

Now, I write the code in code behind. Is there a more sensible place to do that?

도움이 되었습니까?

해결책

Are you just trying to define startup logic for a UserControl?

Then it depends what you're trying to initialize:

  • Are you trying to initialize all sorts of UI-related data?

The best solution would be either in the constructor, or in the Loaded event in code behind

  • Are you trying to initialize the underlying data for its ViewModel?

Then you should create it when you call the UserControl from your parent app. It should initialize your ViewModel and its data, and ilnk it to the UserControl you're trying to load

Should be enough to get you started!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top