简体   繁体   中英

How to navigate to one Panorama item (pane) to another from selecting a button?

I'm very new to Windows 8 development. For my final year project at University I have to create a Windows 8 phone app - I'm working on the my homepage of the app which I've set up as a panorama page in the MainPage.xaml

I was wondering how can I use the PanoramaControl.DefaultItem property to move from one panorama item to another, from the click of a button?

I have a "Home" panorama item with nav buttons that I would like to navigate to the other panorama items within the same page. One of the panorama items I have set-up is a called "My Advice".

Eg User selects the "My Advice" button which is within the "Home" Panorama item, the app will then go to that specific panorama item ie "My Journal"

Here is the code I have created so far for setting up the panorama items in MainPage.xaml -

<!--Panorama item one-->
        <phone:PanoramaItem Header="Home">


<!-- Homepane Stack Panel-->
<StackPanel x:Name="HomePanel" Grid.Row="1" Margin="0,-42,0,0">
                <Button x:Name="My_Advice" Content="My Advice" HorizontalAlignment="Center" Height="74" Margin="124,0,100,0" 
                        VerticalAlignment="Top" Width="200" Background="#3FFFFFFF" BorderBrush="#3FFFFFFF"/>
                <Button Grid.Row="1" Content="My Journal" HorizontalAlignment="Center" Height="74" Margin="124,0,100,0"
                        VerticalAlignment="Top" Width="200" Background="#3FFFFFFF" BorderBrush="#3FFFFFFF"/>
                <Button Grid.Row="2" Content="My Vibes" HorizontalAlignment="Center" Height="74" Margin="124,0,100,0"
                        VerticalAlignment="Top" Width="200"  Background="#3FFFFFFF" BorderBrush="#3FFFFFFF"/>
                <Button Grid.Row="3" Content="My Guidance" HorizontalAlignment="Center" Height="74" Margin="124,0,100,0"
                        VerticalAlignment="Top" Width="200"  Background="#3FFFFFFF" BorderBrush="#3FFFFFFF"/>
                <Button Grid.Row="4" Content="My Support" HorizontalAlignment="Center" Height="74" Margin="119,0,100,0"
                        VerticalAlignment="Top" Width="200" Background="#3FFFFFFF" BorderBrush="#3FFFFFFF"/>
                <Button Grid.Row="5" Content="Help" HorizontalAlignment="Center" Height="74" Margin="119,0,100,0" 
                         Background="#3FFFFFFF" BorderBrush="#3FFFFFFF" VerticalAlignment="Top" Width="200"/>

            </StackPanel>
        </phone:PanoramaItem>

        <!--Panorama item two-->
        <phone:PanoramaItem Header="My Advice">
            <Grid  Grid.Row="1" VerticalAlignment="Top" Width="399">

                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

         <Button x:Name="My_Anxiety101" Content="My Anxiety Info" Grid.Row="0"       Height="106" Width="255" Background="#3FFFFFFF" BorderBrush="#3FFFFFFF" Tap="My_Anxiety101_Tap"/>  
         <Button x:Name="My_Situations" Content="My Situations" Grid.Row="2" Height="106" Width="255" Background="#3FFFFFFF" BorderBrush="#3FFFFFFF" Tap="My_Situations_Tap"/>

            </Grid>
        </phone:PanoramaItem>

Mainpage.xaml.cs

namespace IME
{

public partial class MainPage : PhoneApplicationPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    //--------------------Navigation Button Event Handlers-

    //My Advice Section
    private void My_Anxiety101_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        NavigationService.Navigate(new Uri("/Advice/MyAnxiety101.xaml", UriKind.Relative));
    }
    private void My_Situations_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        NavigationService.Navigate(new Uri("/Advice/MySituations.xaml", UriKind.Relative));
    }

Please let me know if there's any information missing or something doesn't make sense. Thanks in advance

您需要在每个按钮上添加一个名称,双击它们以创建方法,然后使用NavigationService.Navigate(新Uri等将您发送到您想要的页面上(例如PanoramaPage2)

if you want to navigate to second item:

private void My Advice_Click(object sender, EventArgs e)
{
    ParanomaPageName.SelectedIndex = 1;
}

if you want to navigate to third item:

private void My Advice_Click(object sender, EventArgs e)
{
    ParanomaPageName.SelectedIndex = 2;
}

And so on.

    public enum PanoramaItem
    {
        None = -1, Account, Game, Help
    }

    public void PanoramaNavigateTo(PanoramaItem item)
    {
        panorama.DefaultItem = panorama.Items[(int)item];
    }

    private void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        viewGame.cmdPlay.Click += new RoutedEventHandler(CmdPlayGame);
    }


    private void CmdPlayGame(object sender, RoutedEventArgs e)
    {
        PanoramaNavigateTo(PanoramaItem.Game);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM