【问题标题】:Using ProgressBar with Caliburn.micro将 ProgressBar 与 Caliburn.micro 一起使用
【发布时间】:2013-10-09 05:58:04
【问题描述】:

在我的 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 文档中进行搜索,但在那里找不到一些帮助。

感谢您的帮助

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的回答。对,你的答案有效。但我认为“caliburn”允许它通过约定绑定此属性。
    • 我不这么认为。据我所知,Caliburn.Micro 不支持每个 FrameworkElement 的多个约定
    • 应该有办法设置,ItemsControl绑定了SelectedItem和ItemSource。我希望其他人已经完成了艰苦的工作,但我想我必须自己做......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多