2
votes

I have FrameworkElement, for example Grid, that has children(Cells, implemented in another control). When main Window changes size, i handle sizeChanged in Grid at first, and after that in some of its children. How can i get notify that all children sizeChanged events finished processing? Of course, i can raise other event in child sizeChanged and increase some counter, but for some reasons it is not the best decision.

Can anyone recommend something? Thanks!

1
I think if you instead describe what in general you are trying to accomplish, there may be a more elegant solution. Perhaps involving some way to make things automatically change on a property value or event. - Kep Amun

1 Answers

0
votes

I think you are looking for the UIElement.LayoutUpdated Event. It fires whenever the layout gets updated which is a lot, so I would suggest subscribing to it in a handler for the containers SizeChanged event and unsubscribe in the LayoutUpdated handler.

Example:

    private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        // Size change started.
        LayoutUpdated += Window_LayoutUpdated;
    }

    private void Window_LayoutUpdated(object sender, EventArgs e)
    {
        // Size change completed.
        LayoutUpdated -= Window_LayoutUpdated;
    }