[英]Windows Phone 8: Message box has stopped working?
因此,我使用运动api在应用程序上进行工作并通过事件句柄进行更新。 问题是我在显示消息框时遇到麻烦,我无法理解原因。 基本代码如下:
public MainPage()
{
InitializeComponent();
MessageBox.Show("welcome"); //box not showing
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
motion = new Motion();
motion.TimeBetweenUpdates = TimeSpan.FromMilliseconds(20);
motion.CurrentValueChanged +=
new EventHandler<SensorReadingEventArgs<MotionReading>> (motion_CurrentValueChanged);
motion.Start();
}
void motion_CurrentValueChanged(object sender, SensorReadingEventArgs<MotionReading> e)
{
Dispatcher.BeginInvoke(() => CurrentValueChanged(e.SensorReading));
}
private void CurrentValueChanged(MotionReading e)
{
Thickness mar = characterMain.Margin;
txtblck1.Text = "Yaw " + e.Attitude.Yaw.ToString() + " Pitch " + e.Attitude.Pitch + " Roll " + e.Attitude.Roll;
mar.Left = hor + (e.Attitude.Roll * 200);
mar.Top = vert + (e.Attitude.Pitch * 200);
characterMain.Margin = mar;
bool col = engine1.CDetection_V1(characterMain.Margin.Left, characterMain.Margin.Top, characterMain.Width, characterMain.Height, BadGuy.Margin.Left, BadGuy.Margin.Top, BadGuy.Width, BadGuy.Height);
if (col == true)
{
MessageBox.Show("hit");//this doesnt
num.Text = "hit"; //this works
}
}
好了,问题解决了! 事实证明,问题出在我的手机上,而不是我的代码,或者vs的设置方式不对! 我一直在1020上进行测试,并且在重新安装vs2013之前作为不得已的办法,我决定尝试另一个我知道手机上有消息框的应用程序! 并注意到它没有出现简单的重新启动即可解决此问题,并且我的代码开始工作! 所以看起来WP中的错误必须时不时发生! 感谢大家的帮助,特别是Romasz
尝试在页面的Loaded事件中使用Messagebox.Show()
,而不在构造函数中使用它。
尝试使用以下代码。
protected override void OnNavigatedTo(NavigationEventArgs e)
{
//Your logic
MessageBox.Show("Welcome");
}
在OnNavigatedTo()和MainPage()中使用之间的区别是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.