Hi,
I've worked on a few custom controls now and noticed a fairly annoying trend:
Lets say I have a control that renders its contents when I call a Load function.
When I call the controls Load function from the Load event of a user control the custom control is used in I will usually run into problems because it seems that OnApplyTemplate hasn't been called yet in the chain of events.
If a user control is loaded, why can't I access the functionality of my custom control? Am I not wiring something up right in the custom control?
Basically I have some markup in generic.xaml, set the DefaultStyleKey and then in OnApplyTemplate I set a few member variables to controls I use within the custom control. But OnApplyTemplate doesn't seem to be called until after my user control containing the control is loaded.
So now I've got code littered throughout my custom controls saying: if (someVar != null) {AdjustUI();}
And then I've got code in LayoutUpdated etc to do the same thing.
There has got to be a better way to do this.
Comments anyone?
James