Question

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.

Was it helpful?

Solution

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;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top