ここに私が持っている、
private ICommand AddCommand = new RCommand(p => true, p => Add() );
private void Add()
{
emp = new Employee();
DetailsEntryGrid.DataContext = emp;
EnableControls();
tBoxID.Focus();
tBoxID.SelectAll();
//throw new NotImplementedException();
}
vs2010は、「p」が非静的フィールドを指すことができないというコンパイル時エラーをスローし、グリッドとテキストボックスにアクセスできません..これらのコントロールはwpfです.従業員のオブジェクトも作成できません..
そしてRcommandクラスは..
public class RCommand : ICommand
{
readonly Predicate<object> _CanExecute;
readonly Action<object> _Execute;
public RCommand(Action<object> exe) : this(null,exe)
{
}
public RCommand(Predicate<object> predicate, Action<object> action)
{
if (predicate == null)
throw new ArgumentNullException("execute must be provided");
_Execute = action;
_CanExecute = predicate;
}
public bool CanExecute(object parameter)
{
return _CanExecute == null ? true : _CanExecute(parameter);
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public void Execute(object parameter)
{
_Execute(parameter);
}
}
その Add() メソッドにアクセスしたいのですが、その結果、テキスト ボックスとデータグリッドにアクセスしたいのですが、どのようにすればよいですか?
または、RCommand クラスをどのように持つべきですか?