wpf 相当新,使用 galasoft mvvm 模板。我有两个做同样事情的中继命令,但它们需要设置不同的属性。
我可以做这样的事情吗?
public RelayCommand OpenDestinationCommand { get; private set; }
public RelayCommand OpenSourceCommand { get; private set; }
public MainViewModel(IDataService dataService)
{
OpenSourceCommand = new RelayCommand(() => GetPath(SourcePathPropertyName));
OpenDestinationCommand = new RelayCommand(() => GetPath(DestinationPathPropertyName));
}
private void GetPath(string PropertyName) {
//show a dialog, get the path they select
string newPath = GetPathFromDialog();
//what should this look like? Is this possible?
var Property = GetPropertyByName(PropertyName);
Property.Set(newPath);
}