简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM