Pregunta

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?

¿Fue útil?

Solución

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!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top