首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >System.NotImplementedException误差WPF

System.NotImplementedException误差WPF
EN

Stack Overflow用户
提问于 2016-11-23 13:32:38
回答 1查看 287关注 0票数 0

我有问题,我遵循本教程,在这个链接:communication.htm上我了解了WPF,但是当我执行时,他返回错误:

"Error 1 'MVVMDemo.MyICommand‘不实现接口成员MVVMDemo.MyICommand C:\User\Adriano\documents\visual studio 2013\Projects\MVVMDemo\MVVMDemo\MyICommand.cs 10 11 MVVMDemo“

我不明白问题在哪里..。

代码语言:javascript
复制
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(); 
         } 
      } 
    }
}

它停在里面

代码语言:javascript
复制
public MainWindow()
        {
            InitializeComponent();
        }

错误“类型为'System.NotImplementedException‘的异常发生在MVVMDemo.exe中,但未在用户代码中处理’

EN

回答 1

Stack Overflow用户

发布于 2017-02-15 19:26:14

公共显式添加到事件处理程序中

代码语言:javascript
复制
public event EventHandler CanExecuteChanged = delegate { };

完整的解决方案发布在Github回购https://github.com/vjoks/WPF-MVVM/tree/master/MVVMHierarchiesDemo-pre-Validation

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40765920

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档