Window.Content Property (System.Windows)

Switch View :
ScriptFree
.NET Framework Class Library for Silverlight
Window.Content Property

Gets or sets the root visual element that represents the contents of the window.

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

Visual Basic (Declaration)
Public Property Content As FrameworkElement
C#
public FrameworkElement Content { get; set; }

Property Value

Type: System.Windows.FrameworkElement
The element that represents the window contents.
Exceptions

Exception Condition
NotSupportedException

The application is not running outside the browser.

UnauthorizedAccessException

The current thread is not the user interface (UI) thread.

Remarks

You will typically set this property to a new instance of a user control that you define in XAML, as shown in the example.

Examples

The following Silverlight 5 code example shows how a trusted, out-of-browser application can display an arbitrary user control in a separate window. This example requires a UserControl subclass named DemoUserControl.

Visual Basic

If (Application.Current.IsRunningOutOfBrowser AndAlso _ 
    Application.Current.HasElevatedPermissions)

    Dim newWindow As New Window With
    {
        .Title = "Demo Window # " &
            Application.Current.Windows.Count.ToString(),
        .Height = 300,
        .Width = 300,
        .Top = 0,
        .Left = 0,
        .Content = New DemoUserControl(),
        .Visibility = Visibility.Visible
    }
End If


C#

if (Application.Current.IsRunningOutOfBrowser && 
    Application.Current.HasElevatedPermissions)
{
    var newWindow = new Window()
    {
        Title = "Demo Window # " + 
            Application.Current.Windows.Count.ToString(),
        Height = 300, 
        Width = 300, 
        Top = 0, 
        Left = 0,
        Content = new DemoUserControl(),
        Visibility = Visibility.Visible
    };
}


Version Information

Silverlight

Supported in: 5
Platforms

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

See Also

Reference

Other Resources