我在这里,
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 类..?