The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

FrameworkElement.LayoutUpdated Event

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Occurs when the layout of the Windows Phone visual tree changes.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public event EventHandler LayoutUpdated
<frameworkElement LayoutUpdated="eventhandler"/>

LayoutUpdated is the last object lifetime event to occur in the sequence before a control is ready for interaction. However, LayoutUpdated can also occur at run time during the object lifetime, for a variety of reasons: a property change, a window resizing, or an explicit request (UpdateLayout or ApplyTemplate). The LayoutUpdated event is raised after all possible SizeChanged events in the tree have been raised.

In Windows Phone, this event is not a routed event; it is a standard CLR event that uses EventArgs, not RoutedEventArgs.

LayoutUpdated can occur when the object where the handler is attached does not necessarily change anything in the visual tree under it. For instance, imagine a layout container where there are two elements. If the first object changes a property that forces a new layout, both objects raise LayoutUpdated because the second object might be repositioned even if its own subsidiary layout does not change.

When you handle LayoutUpdated, do not rely on the sender value. For LayoutUpdated, sender is always null, regardless of where the handler is attached. This is to prevent handlers from assigning any meaning to sender, such as implying that it was that specific element that raised the event out of the visual tree. Rather, LayoutUpdated implies that something in the overall Windows Phone visual tree has changed, and each specific object anywhere in the tree has the option of handling this occurrence.

Event ordering is not exactly the same between Windows Phone OS 7.1 and Windows Phone 8. Because of this, the initial LayoutUpdated event does not have the correct dimensions the first time that it is raised on Windows Phone 8. The second time it is raised, the dimensions are correct.

If you use the dimensions in LayoutUpdated, you can work around this difference by first checking that ActualWidth and ActualHeight are greater than 0 and valid. The following example code shows how to handle this difference and it works for both Windows Phone OS 7.1 and Windows Phone 8.

double currentUIERWidth = 0, currentUIERHeight = 0;

void MainPage_LayoutUpdated(object sender, EventArgs e)
    if (LayoutRoot.ActualWidth > 0 && LayoutRoot.ActualHeight > 0 &&
      (LayoutRoot.ActualWidth != currentUIERWidth ||
      LayoutRoot.ActualHeight != currentUIERHeight))
        uiRenderer = new UIElementRenderer(LayoutRoot, (int)LayoutRoot.ActualWidth, (int)LayoutRoot.ActualHeight);
        currentUIERWidth = LayoutRoot.ActualWidth;
        currentUIERHeight = LayoutRoot.ActualHeight;

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone