viewおよびmodelviewオブジェクトがインスタンス化されているため気を散らしています。例: 私はビューVを持っています。listview LVとボタンがあります。ボタンには、パラメータとしてlistview LVが必要です。コマンドCanExecuteメソッドは、listView LVに要素があるかどうかをチェックします。しかし、私が開いたときビューVビューモデルオブジェクトが作成する前にビューVします。だからCanExectureメソッドがのリストビューをチェックすると、それはnullであり、私のボタンは永遠に不可能になります。WPF ViewとModelViewの作成
どのように問題を解決しますか?
EDIT: コマンドの実装:コマンド・インプリメンテーションのようなもののために
public class DelegateCommand : ICommand
{
public event EventHandler CanExecuteChanged;
private readonly Action<object> _execute;
private readonly Func<object, bool> _canExecute;
public DelegateCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
if (execute == null)
{
throw new ArgumentNullException(nameof(execute));
}
this._execute = execute;
this._canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return _canExecute == null || _canExecute(parameter);
}
public void Execute(object parameter)
{
_execute(parameter);
}
public void RaiseCanExecuteChanged()
{
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}
}
あなたはあなたのコマンドimplementaion /あなたがコマンドに使用するフレームワークを投稿できますか? – JanDotNet