将ProgressBar与Caliburn.micro一起使用

时间:2013-10-09 05:58:05

标签: c# wpf progress-bar caliburn.micro

在我的WPF应用程序中,我试图将控件'ProgressBar'中的属性'Maximum'与来自ViewModel的属性绑定(在Caliburn.micro的帮助下)。

查看(xaml):

<ProgressBar x:Name="CurrentProgress"/>

视图模型:

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

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

问题:Caliburn.micro是否有办法绑定最大值。我试图创建一个属性:

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

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

但这不起作用。 我也在Caliburn文档中搜索,但在那里找不到一些帮助。

感谢您的帮助

1 个答案:

答案 0 :(得分:4)

您可以像其他ProgressBar.Maximum一样绑定DependencyProperty。这应该有效:

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

您的x:Name="CurrentProgress"已转换为Value="{Binding Path=CurrentProgress, Mode=TwoWay}",因此此类内容也应有效:

<ProgressBar Value="{Binding Path=CurrentProgress}" Maximum="{Binding Path=MaximumProgress}"/>