2

アプリのボタンをクリックすると、選択イベント ハンドラーに 2 回入ります。理由はありますか?

フロントエンドコード:

<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
        <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" 
                                        Text="New"
                                        x:Name="addIconButton"
                                        Click="addIconButton_Click"/>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

メインのバックエンド コード:

コンストラクタ:

addIconButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
addIconButton.Click +=new EventHandler(addIconButton_Click);

イベント ハンドラー:

private void addIconButton_Click(object sender, EventArgs e)
{
    MessageBox.Show("enters addIcon Main");
    Note note = new Note();
    note.Modified = DateTimeOffset.Now;

    if (note != null)
    {
        Settings.NotesList.Add(note);
        //Settings.NotesList[0] = note;
    }
    Settings.CurrentNoteIndex = 0;
    this.NavigationService.Navigate(new Uri("/DetailsPage.XAML",UriKind.Relative));

    //DetailsPage mynewPage = new DetailsPage(); 
    //this.Content = mynewPage;
}
4

1 に答える 1

2
Click="addIconButton_Click" //in your Front-end code

それで、

addIconButton.Click +=new EventHandler(addIconButton_Click);

クリック ハンドラーを 2 回追加していませんか?

于 2012-11-03T23:08:28.690 に答える