I have a WPF / XAML window containing a ComboBox that gives me problems.
The ComboBox window disables the SelectionChanged event. The Debugger column shows me that SelectionChanged is being called (indirectly) from the Window Constructor.
The problem is that there is a Window_Loaded event in the window that does some final initialization of the data members. Since this final initialization is not yet complete, the SelectionChanged event fails with an exceptional exception.
There are several ways to solve this problem, but I would like to know the "most correct" way.
I can completely initialize all my data members in the constructor. This violates the concept of minimally saving constructors.
I could code the SelectionChanged event handler to correctly handle some data members that are null. This coding is for solving only a startup problem that will never occur after a window is completely created.
I could make Lazy-Loaded data members, so they are not initialized by Window_Loaded , but rather, when they are first available. There seems to be little work to solve a problem that can be solved more simply.
I guess I'm not the first person to deal with UI events before the Window Loaded event. What is the preferred way to handle this?
source share