Share via


LayoutInformation Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Defines methods that provide additional information about the layout of an element.

Inheritance Hierarchy

System.Object
  System.Windows.Controls.Primitives.LayoutInformation

Namespace:  System.Windows.Controls.Primitives
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public NotInheritable Class LayoutInformation
public static class LayoutInformation

The LayoutInformation type exposes the following members.

Methods

  Name Description
Public methodStatic memberSupported by Silverlight for Windows Phone GetLayoutClip Returns the visible region of the specified element.
Public methodStatic memberSupported by Silverlight for Windows Phone GetLayoutExceptionElement Returns the element that was being processed by the layout system at the moment of an unhandled exception.
Public methodStatic memberSupported by Silverlight for Windows Phone GetLayoutSlot Returns the layout slot, or bounding box, that contains the specified element.

Top

Remarks

The LayoutInformation class provides the GetLayoutSlot, GetLayoutClip, and GetLayoutExceptionElement methods to help you understand and debug the layout behavior of your Silverlight-based application.

GetLayoutSlot and GetLayoutClip return information about an element's bounding box and visible region. GetLayoutExceptionElement helps you determine where an exception is coming from during layout.

Examples

The following example shows how to use GetLayoutSlot and draw the bounding box for the Rectangle.

Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    'Get Layout Slot of Rectangle 
    Dim r1 As Rect = LayoutInformation.GetLayoutSlot(rect1)
    Dim rg1 As New RectangleGeometry()
    rg1.Rect = r1
    Dim mypath As New Path()
    mypath.Data = rg1
    mypath.Stroke = New SolidColorBrush(Colors.Black)
    mypath.StrokeThickness = 4
    LayoutRoot.Children.Add(mypath)
End Sub
private void Button_Click(object sender, RoutedEventArgs e)
{
    //Get Layout Slot of Rectangle
    Rect r1 = LayoutInformation.GetLayoutSlot(rect1);
    RectangleGeometry rg1 = new RectangleGeometry();
    rg1.Rect = r1;
    Path mypath = new Path();
    mypath.Data = rg1;
    mypath.Stroke = new SolidColorBrush(Colors.Black);
    mypath.StrokeThickness = 4;
    LayoutRoot.Children.Add(mypath);
}
<StackPanel x:Name="sp1" Grid.Row="0" Background="LightBlue" Height="100" Width="200" HorizontalAlignment="Left" VerticalAlignment="Top" >
    <Rectangle x:Name="rect1" Fill="Blue"  Width="100" Height="50" ></Rectangle>
</StackPanel>
<Button Content="Get Layout Slot" Grid.Row="1" Width="150" Height="50" Click="Button_Click" HorizontalAlignment="Left"/>

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.