ChildWindow.Title Property

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

Gets or sets the title of the ChildWindow.

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

Syntax

'Declaration
Public Property Title As Object
public Object Title { get; set; }
<sdk:ChildWindow Title="string"/>
-or-
<sdk:ChildWindow Title="objectReference"/>

XAML Values

Property Value

Type: System.Object
The title of the child window. The default is nulla null reference (Nothing in Visual Basic).

Remarks

Dependency property identifier field: TitleProperty

You can set the Title to be any object. This lets you create complex titles with text, graphics, and animations. If the object does not have a visual representation, the string representation of the object returned by the ToString method will be shown in the title bar.

Examples

The following example demonstrates how to set a simple text Title in XAML. This example is part of a larger example available in the ChildWindow class overview.

<!-- NOTE: 
  By convention, the sdk prefix indicates a URI-based XAML namespace declaration 
  for Silverlight SDK client libraries. This namespace declaration is valid for 
  Silverlight 4 only. In Silverlight 3, you must use individual XAML namespace 
  declarations for each CLR assembly and namespace combination outside the scope 
  of the default Silverlight XAML namespace. For more information, see the help 
  topic "Prefixes and Mappings for Silverlight Libraries". 
-->
<sdk:ChildWindow x:Class="ChildWindowLogin.LoginWindow"
           xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:sdk="https://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
           Width="300" Height="200" 
           Title="Login Window"
           Closing="ChildWindow_Closing">

The following example demonstrates how to set a complex Title in code. The title consists of a StackPanel that contains an image and text.

Run this sample

<UserControl x:Class="ChildWindowTitle.MainPage"
    xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <UserControl.Resources>

    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel Margin="10">
            <TextBlock Text="Enter a title for the child window:" />
            <TextBox x:Name="titleText" />
            <Button Content="Show Child Window" Click="Button_Click"
                    Height="23" Width="125" HorizontalAlignment="Left"
                    Margin="0,4,0,0"/>
        </StackPanel>
    </Grid>
</UserControl>
Imports System.Windows.Media.Imaging

Partial Public Class MainPage
    Inherits UserControl

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim childWindow As New ChildWindow()
        childWindow.Title = GetTitle(titleText.Text)
        childWindow.Content = "Child Window Content."
        childWindow.Show()
    End Sub

    Private Function GetTitle(ByVal title As String) As StackPanel

        ' Logo image.
        Dim logoBrush As New ImageBrush
        logoBrush.ImageSource = New BitmapImage(New Uri("Silverlight.jpg", UriKind.Relative))

        ' Container for logo image.
        Dim logo As New Ellipse
        logo.Height = 24
        logo.Width = 24
        logo.Fill = logoBrush

        ' Title text.
        Dim titleText As New TextBlock
        titleText.Text = title
        titleText.VerticalAlignment = Windows.VerticalAlignment.Bottom

        'Container for logo and text.
        Dim titlePanel As New StackPanel()
        titlePanel.Orientation = Orientation.Horizontal
        titlePanel.Children.Add(logo)
        titlePanel.Children.Add(titleText)

        Return titlePanel
    End Function
End Class
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ChildWindowTitle
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ChildWindow childWindow = new ChildWindow();
            childWindow.Title = GetTitle(titleText.Text);
            childWindow.Content = "Child Window Content.";
            childWindow.Show();
        }

        private StackPanel GetTitle(string title)
        {
            // Logo image.
            ImageBrush logoBrush = new ImageBrush();
            logoBrush.ImageSource = new BitmapImage(new Uri("/Silverlight.jpg", UriKind.Relative));

            // Container for logo image.
            Ellipse logo = new Ellipse();
            logo.Height = 24;
            logo.Width = 24;
            logo.Fill = logoBrush;

            // Title text.
            TextBlock titletext = new TextBlock();
            titletext.Text = title;
            titletext.VerticalAlignment = VerticalAlignment.Bottom;

            // Container for logo and text.
            StackPanel titlePanel = new StackPanel();
            titlePanel.Orientation = Orientation.Horizontal;
            titlePanel.Children.Add(logo);
            titlePanel.Children.Add(titletext);

            return titlePanel;
        }
    }
}

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.