Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ProgressBar with Caliburn.micro

In my WPF application I'm trying to bind the property 'Maximum' from the control 'ProgressBar' with a property from the ViewModel (with help of Caliburn.micro).

View (xaml):

<ProgressBar x:Name="CurrentProgress"/>

ViewModel:

private int currentProgress;
public int CurrentProgress
{
  get { return currentProgress; }
  set
  {
    if (currentProgress == value)
    {
      return;
    }

    currentProgress = value;
    NotifyOfPropertyChange(() => CurrentProgress);
  }
}

The question: Is there a way with Caliburn.micro to bind also the maximum value. I tried to create a property like:

private int maximumProgress;
public int MaximumProgress
{
  get { return maximumProgress; }
  set
  {
    if (maximumProgress == value)
    {
      return;
    }

    maximumProgress = value;
    NotifyOfPropertyChange(() => MaximumProgress);
  }
}

But this does not work. I was also searching in the Caliburn documentation, but wasn't able to find some help there.

Thanks for your help

like image 447
rhe1980 Avatar asked Oct 09 '13 05:10

rhe1980


1 Answers

You can bind ProgressBar.Maximum like every other DependencyProperty. This should work:

<ProgressBar x:Name="CurrentProgress" Maximum="{Binding Path=MaximumProgress}"/>

Your x:Name="CurrentProgress" is converted into Value="{Binding Path=CurrentProgress, Mode=TwoWay}" so something like this should also work:

<ProgressBar Value="{Binding Path=CurrentProgress}" Maximum="{Binding Path=MaximumProgress}"/>
like image 97
dkozl Avatar answered Oct 19 '22 20:10

dkozl