簡體   English   中英

Windows Phone 8:消息框已停止工作?

[英]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()中使用之間的區別是:

  1. 該代碼僅在MainPage(){}中運行一次。 即使您返回MainPage.xaml,代碼也不會運行。
  2. 而每次您導航到MainPage.xaml時,OnNavigatedTo()中的代碼將運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM