WP8 InvalidOperation
Я получаю:
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 ответа
Решение
Это потому, что вы не установили Text
собственность для кнопки.
ApplicationBarIconButton backButton = new ApplicationBarIconButton(new Uri("/Images/back.png", UriKind.Relative));
backButton.Text = "Previous"; //<< you have nextButton.Text
Эй, проблема в том, что вы на самом деле не устанавливаете текст для кнопки "Назад", вы установили nextButton.Text на оба:)