我正在开发一个小型游戏类型的应用程序,当用户赢得游戏时,他将获得弹出窗口,为此我编写了以下代码。
public void stoptimer()
{
if ((Convert.ToString(b1.Content) == "1") && (Convert.ToString(b2.Content) == "2") && (Convert.ToString(b3.Content) == "3") && (Convert.ToString(b4.Content) == "4") && (Convert.ToString(b5.Content) == "5") && (Convert.ToString(b6.Content) == "6") && (Convert.ToString(b7.Content) == "7") && (Convert.ToString(b8.Content) == "8") && (Convert.ToString(b9.Content) == "9") && (Convert.ToString(b10.Content) == "10") && (Convert.ToString(b11.Content) == "11") && (Convert.ToString(b12.Content) == "12") && (Convert.ToString(b13.Content) == "13") && (Convert.ToString(b14.Content) == "14") )
{
newTimer.Stop();
time = txtClock.Text;
//textBox2.Text = txtClock.Text;
Popup buyNowScreen;
buyNowScreen = new Popup();
buyNowScreen.Child =
new popupscreen
();
buyNowScreen.IsOpen = true;
buyNowScreen.VerticalOffset = 100;
buyNowScreen.HorizontalOffset = 25;
}
}
我编写了以下代码用于从弹出页面导航到其他页面,但它无法获取 NullReferenceException。
private void button3_Click(object sender, RoutedEventArgs e)
{
ClosePopup();
NavigationService.Navigate(new Uri("/Menu.xaml", UriKind.Relative));
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ClosePopup();
NavigationService.Navigate(new Uri("/NumericEasy.xaml", UriKind.Relative));
}
private void ClosePopup()
{
Popup buyPop = this.Parent as Popup;
if (buyPop.IsOpen)
{
buyPop.IsOpen = false;
}
}