error loading Progressring (Mahapps)

Asked

Viewed 13 times

0

I have a Progressring on a Page in WPF that needs to be displayed while the Grid is being loaded (Goal: Show the user that you are loading) and then be disabled when loading it has been completed. Only you’re making that mistake:

inserir a descrição da imagem aqui

 public ClienteListPage()
        {
            InitializeComponent();
            carregar();
        } 
        
        public void carregar()
        {
            prProgresso.IsActive = true;
            Task.Factory.StartNew(() =>
            {
                DataContext = App.container.GetService<IClientesListarController>();
            }).ContinueWith(task =>
            {
                prProgresso.IsActive = false;
                if (task.IsFaulted)
                {
                    Console.WriteLine("{0} Exception caught.", task.Exception);
                    MessageBox.Show("Error");
                }
            }, System.Threading.CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }

Someone knows how to help me?

1 answer

0

You’re in trouble because you’re running this in another thread.

o . NET has a class called Backgroundworker, which provides methods to report thread progress in an event. The event is automatically called in the topic that created the Backgroundworker (usually the UI segment).

Use this event "Progresschanged" and update the progress bar in this event handler.

  • Thanks for the return Thiago, but I can’t find this component in my Tools box. It works with WPF even?

  • add the reference to using System.Componentmodel; more information here: https://stackoverflow.com/questions/5483565/how-to-use-wpf-background-worker

Browser other questions tagged

You are not signed in. Login or sign up in order to post.