views:

40

answers:

1

Here is a problem: after loading some visual elements, I need to change something knowing their new sizes. There is MeasureOverride method, but it is called before changing the size. Is there any method that is called after it?

P.S. I know that I can calculate new sizes having old ones, but new sizes aren't calculated simply. It would be much easier to just use such an event (if it exists).

+2  A: 

Are you looking for the FrameworkElement.SizeChanged event?

MSDN's description:

Occurs when either the ActualHeight or the ActualWidth properties change value on a FrameworkElement.

EDIT:

This article has a good description of both the SizeChanged and LayoutUpdated events, including an overview of how the layout loop works.

Donut
Thanks for article, but unfortunately it also occurs before elements are resized.
Sergey
"SizeChanged is raised whenever the size (either ActualHeight or ActualWidth) has changed on the object, and is raised after the Measure and Arrange passes are complete." - So it does happen AFTER element resized.
Denis
>> "So it does happen AFTER element resized."I wish it was true, because it would simplify my work a lot. I tried this event on my application and experimentally found that it occurs before actual resizing.>>"SizeChanged is raised whenever the size (either ActualHeight or ActualWidth) has changed on the object, and is raised after the Measure and Arrange passes are complete."Having read this quotation, I suppose that everything happens in the following order: Measure - Arrange - SizeChanged - actual resizing of the visual objects.
Sergey
@Sergey, you keep saying that it occurs before. Are you sure it's not just being called multiple times? If you put a breakpoint in the `SizeChanged` event handler, it might *appear* to only happen "before actual resizing." However, this event continues to be called each time the size is updated.
Donut
>> Are you sure it's not just being called multiple times? I'm sure it is called 1 time per resize. Let me explain my test. I just put MessageBox.Show(this.View.PlotRect.Width.ToString()) to SizeChanged event handler. When I maximize the window, MessageBox shows 559. When I make window smaller, it shows 1160. (Visual element become bigger when window becomes bigger).
Sergey
Thank you for the article! Now I understand my mistake: I should have used e.NewSize, not something like this.Size!
Sergey