I thought the Loaded event should only fire when the control is just about to render?
When I programmatically add a tab to the TabControl with a UserControl on it, the Loaded event of the UserControl fires although the tab isn't selected and thus the UserControl shouldn't be rendered.
I'm also asking because I then have the problem that when I set the SelectedItem of the TabControl to be the newly added Tab, the Loaded event of the UserControl gets fired yet again.
So in the process of adding and selecting the tab, the Loaded event of the UserControl gets fired twice which isn't desirable.
Edit: It does only seem to happen if the first tab is added to the TabControl for the first time.
Why is that, and is there a better way to prevent this from happening without resorting to some sort of boolean flag testing solution in the Loaded event handler?
When I programmatically add a tab to the TabControl with a UserControl on it, the Loaded event of the UserControl fires although the tab isn't selected and thus the UserControl shouldn't be rendered.
I'm also asking because I then have the problem that when I set the SelectedItem of the TabControl to be the newly added Tab, the Loaded event of the UserControl gets fired yet again.
So in the process of adding and selecting the tab, the Loaded event of the UserControl gets fired twice which isn't desirable.
Edit: It does only seem to happen if the first tab is added to the TabControl for the first time.
Why is that, and is there a better way to prevent this from happening without resorting to some sort of boolean flag testing solution in the Loaded event handler?