I have a Canvas that acts as a background image, let's call this bgCanvas. I also have another Canvas that contains a TextBlock, let's call this fgCanvas. bgCanvas always exists in the scene. An event is raised and as a result, I create a fgCanvas and add it to bgCanvas's children collection. Before I add it though, I wire-up fgCanvas.Loaded because I need to check it's ActualHeight property and you can't do that before it's calculated. So the idea is, create this canvas, wire up it's Loaded event, then add it and wait for the event to fire, then retrieve ActualHeight. Problem is Loaded never fires. I can visually see fgCanvas on the screen so Load must have occurred right? But the handler is never invoked. I tried LayoutUpdated but that fires way too often and it's a plain EventHandler with sender always null. I wish there was a SizeCalculated event or something.. any ideas?
I worked around this by simplifying and such. I have the bgCanvas and I subclassed TextBlock which will lay on top. In the subclass I override OnRenderSizeChanged() and raise a custom event. This gets me the ActualHeight as soon as it's calculated. I didn't plan on having to create a custom eventhandler delegate and event args but unfortunately OnRenderSizeChanged() uses SizeChangedInfo yet RenderSizeEventHandler uses RenderSizeEventArgs and the two are not interchangeable. Not only that but when I tried to instantiate a RenderSizeEventArg I got an error saying there is no constructor defined.. WHAT? So in the end I had to roll my own TextBlock subclass, eventargs, and eventhandler. But it works and that's all that matters right? I'd still like to know why that Canvas was being rendered on the screen but Loaded was never firing....