0

在 MainPage 我有一个按钮。当用户单击该按钮时,我正在初始化进度指示器变量。但它没有初始化,并且在调试时显示为空。那么,我们应该如何在 windows phone 8 中为某些任务显示进度指示器。

下面是我的代码。

ProgressIndicator pi;

private void search_button_clicked(object sender, RoutedEventArgs e)
{
    pi = Microsoft.Phone.Shell.SystemTray.ProgressIndicator;
    //Show the indicator
    pi.IsVisible = true;//Here I'm getting null reference exception

    ........here the code for download xml file by calling web service............
}

我不明白为什么进度指示器变量没有初始化。

4

1 回答 1

0

你可以试试这个...

        private void ShowProgressIndicator(String msg)
        {
            if (ProgressIndicator == null)
            {
                ProgressIndicator = new ProgressIndicator();
                ProgressIndicator.IsIndeterminate = true;
            }

            ProgressIndicator.Text = msg;
            ProgressIndicator.IsVisible = true;
            SystemTray.SetProgressIndicator(this, ProgressIndicator);
        }


        private void HideProgressIndicator()
        {
            ProgressIndicator.IsVisible = false;
            SystemTray.SetProgressIndicator(this, ProgressIndicator);
        }

然后在您的按钮中单击

private void search_button_clicked(object sender, RoutedEventArgs e)
{
  ShowProgressIndicator("Searching");
}

我希望这可以帮助你.....

于 2013-06-28T11:37:34.997 回答