ericlee
ericlee

Reputation: 2753

How to programatically set selected Panorama item header?

For example: I have a header that is called menu 1 and menu 2

How do I change the text in code?

Upvotes: 1

Views: 1109

Answers (1)

Emond
Emond

Reputation: 50672

If you add content to the Panorama statically (in the designer) you can access the headers like this:

<Grid x:Name="LayoutRoot" Background="Transparent">

    <controls:Panorama Title="my application" x:Name="MyPanorama">
        <controls:Panorama.Background>
            <ImageBrush ImageSource="PanoramaBackground.png"/>
        </controls:Panorama.Background>

        <controls:PanoramaItem Header="first item">

Code:

var panoramaItem = MyPanorama.Items[0] as PanoramaItem;
if (panoramaItem != null)
{
    panoramaItem.Header = "New Title";
}

Or, if you want the current PanoramaItem to change its Header:

var panoramaItem = MyPanorama.SelectedItem as PanoramaItem;
if (panoramaItem != null)
{
    panoramaItem.Header = "New Title";
}

Or, when you assign the PanoramaItem a name like this:

<controls:Panorama Title="my application" x:Name="MyPanorama">
    <controls:Panorama.Background>
        <ImageBrush ImageSource="PanoramaBackground.png"/>
    </controls:Panorama.Background>

    <controls:PanoramaItem Header="first item" x:Name="FirstItem">

Then you could code:

FirstItem.Header = "New Title";

When you use DataBinding to create the PanoramaItems you can just change the property of the data object/ViewModel that is bound to the header and it will update automatically.

Upvotes: 2

Related Questions