I have a Silverlight application which has on it a Canvas. On that Canvas, I dynamically "paint" a bunch of stuff, but adding controls to the canvas.
I have a button outside the Canvas area which clears the content. The objects are removed (successfully). However, the Canvas area does not refresh itself immediately; it currently requires a MouseOver or other event for the Canvas itself.
What is the simplest way to have an external object invalidate a Canvas? I'm sure I'm missing something simple!
It's a bit grubby, but you could try changing the visibility to 'Visible' (even though it already is) of the Canvas, so:
myCanvas.Visibility = Visibility.Visible;
We've found that this forces as redraw, even if the actual value of myCanvas.Visible hasn't changed...
Give it a go, it's only a one liner that may fix things. Although I would expect the Canvas to be redrawing anyway if you're removing things from it.
In case someone comes along after the fact like I did looking for this answer...
yourFrameworkElement.InvalidateArrange();
yourFrameworkElement.UpdateLayout();
worked for me.
Note: calling only this.yourFrameworkElement.UpdateLayout();
did not work for me. I had to call InvalidateArrange()
. I called UpdateLayout()
immediately thereafter for completeness - probably has zero real impact.
Also the myCanvas.Visibility = Visibility.Visible;
trick did not work for me as I was trying to cause the LayoutUpdated event to fire.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With