2014-02-12 40 views
0

所以即时通讯使用运动api和通过事件句柄更新的应用程序。问题是我有麻烦让消息框显示,我不明白为什么。以下基本代码:使用Windows Phone 8:消息框已停止工作?

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 
      } 


    } 
+0

你能检查这个例子http://sdrv.ms/1c0rRXI吗? – Romasz

+0

添加到我的代码和测试,但仍然没有运气,谢谢反正队友 –

+0

正如你已经运行的例子(没有修改它) - 有MessageBox工作? – Romasz

回答

2

好吧所以问题解决了!原来这个问题不是我的代码,或者vs是如何设置的,它实际上是我的手机!我一直在测试我的1020,并且在重新安装vs2013之前作为最后的手段,我决定尝试另一个应用程序,我知道我的手机上有一个消息框!并注意到它没有出现一个简单的重新启动解决这个问题,我的代码开始工作!所以它看起来像WP中的一个错误,必须时不时地发生!感谢大家的帮助,特别是Romasz

1

尝试的Messagebox.Show()Loaded事件的页面,而不是在构造函数中使用它..

+0

拼写错误... – stackamar

1

尝试使用下面的代码。使用的OnNavigatedTo()和的MainPage(之间

protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
     //Your logic 
     MessageBox.Show("Welcome"); 
    } 

差):

  1. 代码将运行在仅一次的MainPage(){}。尽管你回到MainPage.xaml,代码将不会运行。
  2. 然而,每当您导航到MainPage.xaml时,OnNavigatedTo()中的代码都会运行。
+0

感谢您的回复,该位只是一个测试主要位我有一个问题是在代码的底部位。 –