freshbm
freshbm

Reputation: 5622

How to use PanoramaItem for navigation

I'm trying to use PanoramaItem Header for navigation in my App. I named other pages with header names and override HeaderTemplate for Panorama control in my start page.

<controls:Panorama Title="PanoramaApp" 
                   HeaderTemplate="{StaticResource PanoramaHeaderItemTemplate}">

            <controls:PanoramaItem Header="Item1">
                          ...
            </controls:PanoramaItem>
</controls:Panorama>

and

<DataTemplate x:Key="PanoramaHeaderItemTemplate">
      <Button Style="{StaticResource PanoramaHeaderItemStyle}"
              Click="PanoramaHeaderItem_Click"/>
</DataTemplate>

My problem is: How to get panorama HeaderItem value in code behind? In this case it would be Item1.

This is my code so far:

private void PanoramaHeaderItem_Click(object sender, RoutedEventArgs e)
        {
            var button = (Button)sender;
            var HeaderName = ???
        }

I don't know hot to get that header name and use it to navigate to other page.

Upvotes: 0

Views: 248

Answers (1)

Shawn Kendrot
Shawn Kendrot

Reputation: 12465

you have two options to get the content from the button

  1. Get the DataContext of the button

    MyObject myObj = button.DataContext as MyObject;

  2. Get Content property of the button

    object content = button.Content;

Upvotes: 1

Related Questions