0

Windows Phone プロジェクトの 3 つの異なるスタック パネル (button1、button2、button3) に 3 つのボタンをデザインしました。ボタン 1 の可視性プロパティを表示、つまり、visibilty="visible" に設定し、残りのボタンの可視性プロパティを折りたたむように設定しました。これにより、プロジェクトの実行時にメイン ページにボタン 1 のみが表示され、3 つの異なるすべてのコーディングも行いました。ボタン 1 をクリックするとボタン 2 が表示され、ボタン 2 をクリックするとボタン 3 が表示されます。コードは次のとおりです。

private void button1_Click_1(object sender, RoutedEventArgs e)
{
    button1.Visibility = Visibility.Collapsed;
    stackPanel1.Visibility = Visibility.Visible;
}


    private void button2_Click(object sender, RoutedEventArgs e)
    {
        stackPanel1.Visibility = Visibility.Collapsed;
        stackPanel2.Visibility = Visibility.Visible;

    }

ボタン1をクリックするとボタン2が表示され、ボタン2をクリックするとボタン3が表示され、戻るボタン(ハードウェア)をクリックするとボタン2に移動するように、戻るキーボタンを処理したいと思います。もう一度戻るキーをクリックすると、ボタン 1 に移動する必要があります。ボタンをクリックした後に戻るボタンをクリックすると、Windows Phoneのデフォルトの動作であるアプリが閉じられます。私を助けてください。これが私の完全なxamalコードです`

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

        <StackPanel Height="244" HorizontalAlignment="Left" Margin="77,166,0,0" Name="stackPanel1" VerticalAlignment="Top" Width="316">
            <Button Content="Button1" Height="71" Name="button1" Width="160" Click="button1_Click" />
        </StackPanel>

        <StackPanel Height="247" HorizontalAlignment="Left" Margin="129,240,0,0" Name="stackPanel2" VerticalAlignment="Top" Width="267" Visibility="Collapsed">
            <Button Content="Button2" Height="71" Name="button2" Width="160" Click="button2_Click" />
        </StackPanel>



        <StackPanel Height="247" HorizontalAlignment="Left" Margin="129,240,0,0" Name="stackPanel3" VerticalAlignment="Top" Width="267" Visibility="Collapsed">
            <Button Content="Button3" Height="71" Name="button3" Width="160" Click="button3_Click" />
        </StackPanel>

    </Grid>
</Grid>

<!--Sample code showing usage of ApplicationBar-->
<!--<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
        <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
        <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
            <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
        </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>-->

ここに私の.csコードがあります:

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Net;   
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Documents;
 using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Animation;
 using System.Windows.Shapes;
 using Microsoft.Phone.Controls;

  namespace backkeybehave
  {
    public partial class MainPage : PhoneApplicationPage
    {
    // Constructor
    public MainPage()
    {
        InitializeComponent();
    }



    private void button3_Click(object sender, RoutedEventArgs e)
    {


    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        stackPanel1.Visibility = Visibility.Collapsed;
        stackPanel2.Visibility = Visibility.Visible;
    }

    private void button2_Click(object sender, RoutedEventArgs e)
    {
        stackPanel2.Visibility = Visibility.Collapsed;
        stackPanel3.Visibility = Visibility.Visible;
    }


   }
 }
4

2 に答える 2

1

そうしないでください。戻るキーは、ページ内ナビゲーションではなく、バックスタック ナビゲーション用です。

一方、とにかくそれを本当にやりたい場合は、それを見て、PhoneApplicationPage.OnBackKeyPressそれをアプリのロジックに使用してください。

于 2013-04-30T11:55:09.993 に答える
0

onbackkeypress をオーバーライドしたときに何が起こるかを追跡するには、独自のロジックを実装する必要があります。

たとえば、button3 が表示されているときに戻ると、常に button2 が表示される場合は、次のように使用できます。

if (button3.visibility == visibility.visible)
{
  button3.visibility = visibility.collapsed;
  button2.visibility = visibility.visible;
  e.cancel = true;
}

しかし、これは慎重に検討し、考えられるすべてのナビゲーション パスを含める必要があります。

于 2013-05-01T14:15:23.190 に答える