I'm not 100% sure what you're doing (so I may not be answering your question), but in a quick test with a Canvas called bgCanvas already on the form:
public partial class Window1
private Canvas fgCanvas;
private void Button_Click(object sender, RoutedEventArgs e)
fgCanvas = new Canvas();
fgCanvas.Loaded += new RoutedEventHandler(fgCanvas_Loaded);
fgCanvas.Width = 100;
fgCanvas.LayoutUpdated += new EventHandler(fgCanvas_LayoutUpdated);
void fgCanvas_LayoutUpdated(object sender, EventArgs e)
txtSize.Text = fgCanvas.RenderSize.ToString();
void fgCanvas_Loaded(object sender, RoutedEventArgs e)
Both the Loaded and LayoutUpdated events are raised as expected. The sender arg is null though in the LayoutUpdated event -- so I needed to store a reference to the fgCanvas object as a private member variable. The txtSize TextBox I added gets the value of "100,0" when I click a button on the window.
What I'm mostly confused about is that it seems like you're trying to get a size for the Canvas after layout? The Canvas normally doesn't size -- it's content can extend beyond it's boundaries without clipping, so it's size is normally irrelevant.
I don't see any RenderSizeEventHanlder in the 3.0 documentation anywhere .... ? http://www.wiredprairie.us/journal
"znelson" <firstname.lastname@example.org> wrote in message news:email@example.com...
>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....