【问题标题】:ProgressIndicatior is not initializedProgressIndicatior 未初始化
【发布时间】:2013-06-26 01:52:26
【问题描述】:

在 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............
}

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

【问题讨论】:

  • 它始终为空。您需要创建并设置它。

标签: windows-phone-7 windows-phone-8 progress progress-indicator


【解决方案1】:

你可以试试这个...

        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");
}

希望对你有所帮助.....

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-11
    • 2021-12-14
    • 2016-04-02
    • 2020-02-14
    • 2018-09-10
    • 1970-01-01
    相关资源
    最近更新 更多