5
votes

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

1

1 Answers

6
votes

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}"/>