2017-02-18 1 views
1

MVVM을 처음 접했고 뭔가가 있습니다. 제 Xamarin.Forms 앱에서 잘못하고 있습니다.Xamarin ICommand가 실행되지 않습니다.

여기에 내가 명령 "TapCommand"에 연결된 이미지가 SessionsPage.xml

<Grid.Children> 
    <Image Source="zero.jpg" Grid.Row="0" Grid.Column="0"> 
    <Image.GestureRecognizers> 
     <TapGestureRecognizer 
      Command="{Binding TapCommand}" 
      CommandParameter="0" /> 
    </Image.GestureRecognizers> 

에있을거야.

tapViewModel = new EasyScrum.Views.TapViewModel(); 

을 그리고 뷰 모델 클래스는 다음과 같습니다 :이보기의 생성자에서

, 내가 추가

public class TapViewModel : INotifyPropertyChanged 
{ 
    int taps = 0; 
    ICommand tapCommand; 

    public event PropertyChangedEventHandler PropertyChanged; 

    public TapViewModel() 
    { 
     // configure the TapCommand with a method 
     tapCommand = new Command(OnTapped); 
    } 

    public ICommand TapCommand 
    { 
     get { return tapCommand; } 
    } 
    void OnTapped(object s) 
    { 
     taps++; 
     Debug.WriteLine("parameter: " + s); 
    } 
    //region INotifyPropertyChanged code omitted 
} 

그리고 이벤트는, 무엇이 잘못 발사되지 않는 이유는 무엇입니까?

답변

1

나는 스스로 대답합니다.

내 실수는 내가) (

this.BindingContext = 새로운 TapViewModel을 할당해야한다고했다;

관련 문제