我有问题,我遵循本教程,在这个链接:communication.htm上我了解了WPF,但是当我执行时,他返回错误:
"Error 1 'MVVMDemo.MyICommand‘不实现接口成员MVVMDemo.MyICommand C:\User\Adriano\documents\visual studio 2013\Projects\MVVMDemo\MVVMDemo\MyICommand.cs 10 11 MVVMDemo“
我不明白问题在哪里..。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace MVVMDemo
{
class MyICommand : ICommand
{
Action _TargetExecuteMethod;
Func<bool> _TargetCanExecuteMethod;
public MyICommand(Action executeMethod) {
_TargetExecuteMethod = executeMethod;
}
public MyICommand(Action executeMethod, Func<bool> canExecuteMethod){
_TargetExecuteMethod = executeMethod;
_TargetCanExecuteMethod = canExecuteMethod;
}
public void RaiseCanExecuteChanged() {
CanExecuteChanged(this, EventArgs.Empty);
}
bool ICommand.CanExecute(object parameter) {
if (_TargetCanExecuteMethod != null) {
return _TargetCanExecuteMethod();
}
if (_TargetExecuteMethod != null) {
return true;
}
return false;
}
// Beware - should use weak references if command instance lifetime
//is longer than lifetime of UI objects that get hooked up to command
// Prism commands solve this in their implementation public event
EventHandler CanExecuteChanged = delegate { };
void ICommand.Execute(object parameter) {
if (_TargetExecuteMethod != null) {
_TargetExecuteMethod();
}
}
}
}它停在里面
public MainWindow()
{
InitializeComponent();
}错误“类型为'System.NotImplementedException‘的异常发生在MVVMDemo.exe中,但未在用户代码中处理’
发布于 2017-02-15 19:26:14
将公共显式添加到事件处理程序中
public event EventHandler CanExecuteChanged = delegate { };完整的解决方案发布在Github回购https://github.com/vjoks/WPF-MVVM/tree/master/MVVMHierarchiesDemo-pre-Validation上
https://stackoverflow.com/questions/40765920
复制相似问题