In my constructor for my Silverlight 4 page, I call InitializeComponent, followed immediately by this statement:
OriginalDefaultCharts = new Dictionary<Chart, string>{
{ chartTop, ( ( ComboBoxItem ) comboInstant.SelectedItem ).Tag.ToString ( ) },
{ chartBottom, ( ( ComboBoxItem ) comboCumulative.SelectedItem ).Tag.ToString ( ) } };
This almost always works, but occasionally, this statement will throw a Null Exception because comboCumulative is null.
I see where comboCumulative is instantiated in InitializeComponent, but since this usually works but not always, it makes me think that there is something I should be waiting for. Is it typical to put all the constructor logic after InitializeComponent into the Loaded event?
I did that, but since my code only rarely failed before, I’m not 100% sure that I have solved the problem.
You do.
Yes the call to Initialize component is asynchronous (more specifically, the build of the UI components is asynchronous).
Thus this is a really bad practice to perform any opeation on UI elements after the initialize component (actually it is better to not implement aynthing just after InitializeComponent: let your default constructor clean and clear).
The good practice is to perform these operations in the loaded event as you did.
Though, be aware than even in your loaded event, some UI elements (especially the invisble one) will still not be created.