ChildWindow.OnOpened Method

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

This method is called every time a ChildWindow is displayed.

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

Syntax

'Declaration
Protected Overridable Sub OnOpened
protected virtual void OnOpened()

Remarks

The base implementation of OnOpened sets the overlay brush and opacity if an overlay exists, and it makes sure that the child window can be tabbed to with the keyboard.

You can override OnOpened to perform any actions needed by your application when a child window is opened.

Examples

The following code example demonstrates how to override the OnOpened method. This code randomly selects between two different videos to be played when the child window opens. This example is part of a larger example available in the ChildWindow class overview.

Protected Overrides Sub OnOpened()
    MyBase.OnOpened()

    Dim generator As New Random
    Dim randomValue As Integer
    randomValue = generator.Next(0, 2)

    If randomValue = 1 Then
        Me.splashMedia.Source = New Uri("/Silverlight1.wmv", UriKind.RelativeOrAbsolute)
    Else
        Me.splashMedia.Source = New Uri("/Silverlight2.wmv", UriKind.RelativeOrAbsolute)
    End If
End Sub
protected override void OnOpened()
{
    base.OnOpened();

    Random random = new Random();
    if ((int)random.Next(0, 2) == 1)
    {
        this.splashMedia.Source = new Uri("/Silverlight1.wmv", UriKind.RelativeOrAbsolute); ;
    }
    else
        this.splashMedia.Source = new Uri("/Silverlight2.wmv", UriKind.RelativeOrAbsolute);
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

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