WP8 InvalidOperation

时间:2013-08-11 13:08:55

标签: c# windows-phone-8 invalidoperationexception

我得到了:

An exception of type 'System.InvalidOperationException' occurred in Microsoft.Phone.ni.dll but was not handled in user code

当我这样做时:

ApplicationBarIconButton nextButton = new ApplicationBarIconButton(new Uri("/Images/next.png", UriKind.Relative));
nextButton.Text = "Next";

ApplicationBarIconButton backButton = new ApplicationBarIconButton(new Uri("/Images/back.png", UriKind.Relative));
nextButton.Text = "Previous";

ApplicationBar.Buttons.Add(nextButton);
ApplicationBar.Buttons.Add(backButton); //<---- Error when adding this

任何人都可以看到我发生了可怕的错误吗?

2 个答案:

答案 0 :(得分:3)

这是因为您没有为后退按钮设置Text属性。

ApplicationBarIconButton backButton = new ApplicationBarIconButton(new Uri("/Images/back.png", UriKind.Relative));
backButton.Text = "Previous"; //<< you have nextButton.Text

答案 1 :(得分:0)

嘿问题是你实际上没有设置后退按钮的文本,你在两个上都设置了nextButton.Text :)