2012-11-12 75 views
0

如何設置使用繼電器命令聲明MVVM RelayCommand,我用下面的方式,拋出接口錯誤的設置方法如何在視圖模型

 public RelayCommand ChartCommand 
    { 

     set 
     { 
      ChartCommand = new RelayCommand<string>(e => ExecuteChartCommand(e)); 

     } 
    } 
    public void ExecuteChartCommand(string vendor) 
    { 

    } 

回答

2

你真正應該做這種方式:

private RelayCommand<string> m_ChartCommand; 
    public RelayCommand<string> ChartCommand 
    {  
     get 
     { 
      return m_ChartCommand ?? (m_ChartCommand = new RelayCommand<string>(e => ExecuteChartCommand(e));  
     } 
    } 

    public void ExecuteChartCommand(string vendor) 
    { 

    } 

+0

感謝您的另一種方法 –