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.

有帮助吗?

解决方案

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;

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top