[µTip] Establecer el título de página con Silverlight

Si estás usando Navigation Framework de Silverlight te darás cuenta que cada Page tiene su propiedad Title que al momento de ser navegada se establece “eliminando” evidencia del título principal. Para poder modificar este comportamiento, bastará con programar el evento Navigated del control Frame que contiene a cada Page.

Suponiendo que nuestro Frame se llame MainFrame  y tengamos un Page aparte que tenga el título

<navigation:Frame UriMapper="{StaticResource miMapper}" x:Name="MainFrame" Source="Inicio">
</navigation:Frame>
 
<navigation:Page x:Class="Cidesoft.FrameViews.Inicio"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
   Title="Inicio" />
 

agregaremos evento

this.MainFrame.Navigated+=
    new System.Windows.Navigation.NavigatedEventHandler(MainFrame_Navigated);

y luego gracias al objecto HtmlPage de System.Windows.Browser, podremos modificar la propiedad title de la página host.
 
private void MainFrame_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
       string pageTitle = ((Page)e.Content).Title;
       string mainTitle = ".: Cidesoft :.";
       if(!string.IsNullOrEmpty(pageTitle))
            HtmlPage.Document.
                    SetProperty("title",string.Format("{0} - {1}", mainTitle,pageTitle));
       else
            HtmlPage.Document.SetProperty("title",mainTitle);
}

Aparte de este post dejar algunos links sobre Silverlight:

Espero haya sido de utilidad :)

Post.End();

About Jara Gabriel

Integrante Colaborador del CIDESOFT. Microsoft Certified Tecchnology Specialist
This entry was posted in Silverlight and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>