Child Property
Collapse the table of content
Expand the table of content

Viewbox.Child Property

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

Gets or sets the single child element of a Viewbox element.

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

'Declaration
Public Property Child As UIElement
<ViewBox ...>
  child
</ViewBox>

XAML Values

child

A single object element of a type that derives from UIElement, which is contained by this Viewbox.

Property Value

Type: System.Windows.UIElement
The single child element of a Viewbox element.

A Viewbox can have only one Child. If you add an additional Child, an ArgumentException will be thrown at run time. If you want to add multiple controls to a Viewbox, add those controls to a panel element, such as a StackPanel, Grid, or Canvas, and then add the panel element to the Viewbox.

The following example adds two images to a Viewbox control by adding the images to a StackPanel, and then adding the StackPanel to the Viewbox.


<Grid x:Name="LayoutRoot" Background="Transparent">
    <Viewbox Height="500" Width="600">
        <StackPanel Orientation="Horizontal">
            <Image Source="flower.jpg" />
            <Image Source="licorice.jpg" />
        </StackPanel>
    </Viewbox>
</Grid>



private void DisplayViewBox()
{
    Viewbox MyVB = new Viewbox();

    //Setting the Height and Width of the ViewBox
    MyVB.Height = 500;
    MyVB.Width = 600;

    //Defining two image elements
    Image MyImage1 = new Image();
    MyImage1.Source = new BitmapImage(new Uri("flower.jpg", UriKind.RelativeOrAbsolute));
    Image MyImage2 = new Image();
    MyImage2.Source = new BitmapImage(new Uri("licorice.jpg", UriKind.RelativeOrAbsolute));

    //Adding the Image elements to a StackPanel
    StackPanel MySP = new StackPanel();
    MySP.Orientation = System.Windows.Controls.Orientation.Horizontal;
    MySP.Children.Add(MyImage1);
    MySP.Children.Add(MyImage2);

    //Adding the StackPanel to the ViewBox
    MyVB.Child = MySP;

    //Adding the ViewBox to the Grid
    LayoutRoot.Children.Add(MyVB);

}



Private Sub DisplayViewBox()
    Dim MyVB As New Viewbox()

    'Setting the Height and Width of the ViewBox
    MyVB.Height = 500
    MyVB.Width = 600

    'Defining two image elements
    Dim MyImage1 As New Image()
    MyImage1.Source = New BitmapImage(New Uri("flower.jpg", UriKind.RelativeOrAbsolute))
    Dim MyImage2 As New Image()
    MyImage2.Source = New BitmapImage(New Uri("licorice.jpg", UriKind.RelativeOrAbsolute))

    'Adding the Image elements to a StackPanel
    Dim MySP As New StackPanel()
    MySP.Orientation = System.Windows.Controls.Orientation.Horizontal
    MySP.Children.Add(MyImage1)
    MySP.Children.Add(MyImage2)

    'Adding the StackPanel to the ViewBox
    MyVB.Child = MySP

    'Adding the ViewBox to the Grid

    LayoutRoot.Children.Add(MyVB)
End Sub


Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Show:
© 2017 Microsoft