Hi guys,

I've come across this issue before with WPF, and have now hit something
similar in Silverlight. I've got a page with a Canvas element on it called
"pageContents" and I'm loading XAML fragments into the contents of the
Canvas.
That works no problems, but what I'm having issues with is the
pageContents.ActualWidth (and ActualHeight) are not updating. The Canvas
starts off with no content and Width and Height are not set, so default to
Auto. Adding the content automatically sizes the Canvas but the ActualHeight
and ActualWidth are still showing as 0 (zero).

I've got a snippet of code that tells me if the mouse click was inside the
bounds of the Canvas and I need to know the dimensions of the canvas.
Calling pageContents.Measure(availablesize) doesn't seem to help. Any other
tricks I can use?

protected void Page_MouseLeftButtonDown(object sender, MouseEventArgs e) {
    var contentRect = new
Rect((double)pageContents.GetValue(Canvas.LeftProperty),
(double)pageContents.GetValue(Canvas.TopProperty), pageContents.ActualWidth,
pageContents.ActualHeight);
    var position = e.GetPosition(null);
    if (contentRect.Contains(position)) {
        _lastMousePosition = position;
    }
}

thanks,
Stephen



------------------------------------------------------------------- 
OzSilverlight.com - to unsubscribe from this list, send a message back to the 
list with 'unsubscribe' as the subject.
Powered by mailenable.com - List managed by www.readify.net

Reply via email to