当我单击我的应用程序按钮时,它会进入选择事件处理程序两次。知道为什么吗?
前端代码:
<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>
main的后端代码:
构造函数:
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;
}