如何通过选择按钮导航到一个Panorama项目(窗格)到另一个项目(窗格)?

时间:2013-12-05 16:33:50

标签: c# wpf xaml visual-studio-2012 windows-8

我对Windows 8开发非常陌生。对于我在大学的最后一年项目,我必须创建一个Windows 8手机应用程序 - 我正在我的应用程序主页上工作,我已将其设置为MainPage.xaml中的全景页面

我想知道如何使用PanoramaControl.DefaultItem属性从单个按钮上移动一个全景项目到另一个全景项目?

我有一个" Home"导航按钮的全景项目,我想导航到同一页面中的其他全景项目。我设置的全景项目之一是一个名为“我的建议"。

E.g用户选择"我的建议"按钮位于" Home"全景项目,应用程序将转到特定的全景项目,即"我的日记"

以下是我在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));
    }

如果有任何信息丢失或者某些事情没有意义,请告诉我。 提前致谢

3 个答案:

答案 0 :(得分:0)

你需要在每个按钮上加上一个名字,双击它们来制作方法,然后使用NavigationService.Navigate(新的Uri等发送给你你想要的页面(例如PanoramaPage2)

答案 1 :(得分:0)

如果您想导航到第二项:

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

如果你想导航到第三项:

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

等等。

答案 2 :(得分:0)

    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);
    }