这是我的代码:
namespace ns1
Class A()
{
//set interface prop value
_progressBarListner.CurrCount =2;
_progressBarListner.TotalCount =5;
}
Interface IProgressBarListner
{
int CurrCount {get;set;}
int TotalCount {get;set;}
}
public class ProgBarViewModel : BindableBase
{
// binded variable to a label on progress bar
public string ProgressPercentage
{
get => _progressPercentage;
set => SetProperty(ref _progressPercentage, value);
}
// binded variable to value attribute of progress bar
public double ProgressValue
{
get => _progressValue;
set => SetProperty(ref _progressValue, value);
}
//Instead of using this event handler, I would like to consume interface property to set
private void UpdateProgressBar(UpdateProgressBarArgs args)
{
var percentCompleted = (args.CurrentCount / args.TotalCount) * 100;
ProgressValue = percentCompleted;
ProgressPercentage = string.Format(CultureInfo.InvariantCulture, "{0} %", percentCompleted.ToString("0", CultureInfo.InvariantCulture));
}
}
当前,它订阅一个事件并更新进度条视图模型属性。相反,我想使用此接口属性来更新进度条视图模型。我怎么能达到同样的目的?