1
galasoft mvvmテンプレートを使用して、かなり新しいwpfが新しくなりました。 同じことをする2つのrelayコマンドがありますが、それぞれ異なるプロパティを設定する必要があります。プロパティ名でプロパティを設定できますか?
私はこれを行うことはできますか?
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);
}
アンから適応:反射が比較的遅い* * - それは、それがタイトなループやホットパスにないよう大丈夫です。もしそうなら:より速いオプションがあります - あなたがこれを必要とするかどうか私に教えてください。 –
もしあなたがより良い答えを持っていれば、それがあります!あまりにも多くの時間を費やすことはありませんが、perfは間違いなくここでは問題ではありません。 – scaryman
wpfやmvvmのライトに何かが組み込まれていたら、私はほとんど興味がありました。私は完全にゾーン化して、質問を投稿したときの反射を忘れました。 – scaryman