jonniebigodes
jonniebigodes

Reputation: 137

caliburn micro update progress bar using task

i'm having this problem, been using caliburn micro and i'm trying to update my progress bar. but nothing it's happening. i've read a couple of threads in here about it and i'm stuck, it just doesn't update

could you see what's wrong with my code? my xaml is this:

<ProgressBar x:Name="PbEstadoConfig" FlowDirection="LeftToRight" Width="200" Height="30" Margin="6,0,572,0">

and in my view model i have the following code:

private double _pbEstadoConfig;
            public double PbEstadoConfig
            {
                get { return _pbEstadoConfig; }
                set
                {
                    _pbEstadoConfig = value;
                    NotifyOfPropertyChange(() => PbEstadoConfig);
                }
            }

     public void Seguinte()
            {
                var t = Task.Factory.StartNew(() =>ActualizaPB("seguinte"));


            }
    protected void ActualizaPB(string value){
     PbEstadoConfig += 20.0;

}

Upvotes: 1

Views: 1643

Answers (2)

voidmain
voidmain

Reputation: 1611

My experience with WPF MVVM programming such as that provided by Caliburn.Micro is that the UI thread will be locked during a long running routine, so the progress bar will not update during a long running routine since that it's on the same thread. As such, I followed the advice on this page from Stephen, and implemented his ProgressReporter class along with the System.Threading library

Upvotes: 1

Rhys Bevilaqua
Rhys Bevilaqua

Reputation: 2167

I think it may be your lack of maximum/minimum values on your progressbar.

The following is working markup in a caliburn micro project i'm currently working on, I have not had to write any custom conventions

    <ProgressBar Name="Progress" Maximum="1" Minimum="0" Margin="0,22,0,0" Grid.Row="1" Height="20"  Grid.ColumnSpan="2"></ProgressBar>

And the backing property:

    public double Progress
    {
        get { return _progress; }
        set
        {
            _progress = value;
            NotifyOfPropertyChange(() => Progress);
        }
    }

Upvotes: 1

Related Questions