Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Viewbox.Child Property

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

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

public UIElement Child { get; set; }
<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="White">
    <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 = 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 = 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


Silverlight

Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

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

Community Additions

ADD
Show:
© 2015 Microsoft