Share via

Progress ring not showed

BitSmithy 2,231 Reputation points
2022-03-09T17:38:39.013+00:00

Hello,

I have problem with ProgressRing it doesnt show when I want to show it.

My XAML:

                <Button x:Name="btnRefreshData" 
                        Click="BtnRefreshData_Click"
                        ></Button>


                <ProgressRing x:Name="prrgLoadingData"></ProgressRing>

My code behind

    private async void BtnRefreshData_Click(object sender, RoutedEventArgs e)
    {
        RefreshData();
    }


    private async void RefreshData()
    {

        prrgLoadingData.IsActive = true;
        prrgLoadingData.Visibility = Visibility.Visible;

            await LoadReportDataFromSQLDB(); //it loads data from sql db

        prrgLoadingData.IsActive = false;
        prrgLoadingData.Visibility = Visibility.Collapsed;

}

I read in net that should be done in another way, but I dont know how to do it in my case.
How to do that in proper way?

Developer technologies | Universal Windows Platform (UWP)

Answer accepted by question author

  1. Anonymous
    2022-03-11T02:09:03.453+00:00

    Hello,

    Welcome to Microsoft Q&A!

    After testing, add a Task.Delay() method will help to solve the issue.

    The code looks like this:

                 prrgLoadingData.IsActive = true;  
                 prrgLoadingData.Visibility = Visibility.Visible;  
          
                 await Task.Delay(1);  
      
                 await LoadReportDataFromSQLDB(); //it loads data from sql db  
          
                 prrgLoadingData.IsActive = false;  
                 prrgLoadingData.Visibility = Visibility.Collapsed;  
    

    If you have any other questions, please let us know.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Castorix31 91,871 Reputation points
    2022-03-09T18:14:24.16+00:00

    This test based on your code works for me : test with a 5 seconds Task =>

    181554-progressring.gif

     <ProgressRing x:Name="prrgLoadingData" Height="40" Width="40">              
     </ProgressRing>  
    

    Test code :

        private async void BtnRefreshData_Click(object sender, RoutedEventArgs e)  
        {  
            RefreshData();  
        }  
    
        private async void RefreshData()  
        {  
            prrgLoadingData.IsActive = true;  
            prrgLoadingData.Visibility = Visibility.Visible;  
            await MyTask();  
        }  
    
        async System.Threading.Tasks.Task MyTask()  
        {  
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>  
            {  
                await System.Threading.Tasks.Task.Delay(5000);  
                prrgLoadingData.IsActive = false;  
                prrgLoadingData.Visibility = Visibility.Collapsed;  
                MessageDialog dialog = new MessageDialog("Task finished !", "Information");                 
                _ = dialog.ShowAsync();                 
            });  
        }  
    

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.