2013-07-06 149 views
1

我用MVVM,鑑於旁邊代碼:Windows Phone中不起作用自來水事件圖像8

<Image Source="Content/img/heart_gray.png" Width="25" Height="25" Margin="0,0,5,0" HorizontalAlignment="Right" Visibility="{Binding LikeVisability}"> 
               <i:Interaction.Triggers> 
                <i:EventTrigger EventName="Tap"> 
                 <cmd:EventToCommand Command="{Binding SetLikeCommand}" /> 
                </i:EventTrigger> 
               </i:Interaction.Triggers> 
              </Image> 

在視圖模型:

私人RelayCommand setLike;

 public ICommand SetLikeCommand 
    { 
     get 
     { 
      return this.setLike ?? (this.setLike = new RelayCommand(this.SetLike)); 
     } 
    } 


    private void SetLike() 
    { 
     var t = "fsdf"; 
    } 

當我在方法SetLike()中放置斷點時,程序沒有停止當我點擊圖像。也許我在視圖中做了什麼錯誤,綁定事件在哪裏?請幫忙!

+0

將斷點的制定者,調用它呢? –

+0

爲什麼不使用一個只顯示圖像的按鈕(無邊框)? –

+0

我把斷點放在setter上,但它不起作用。 – Pisha91

回答

1

你所顯示的代碼沒有什麼根本性的錯誤,它只是不足以顯示你的問題。

下不工作:

XAML:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
    <Image Source="Assets/ApplicationIcon.png" Width="25" Height="25" Margin="0,0,5,0" 
      HorizontalAlignment="Right" Visibility="{Binding LikeVisability}"> 
     <i:Interaction.Triggers> 
      <i:EventTrigger EventName="Tap"> 
       <cmd:EventToCommand Command="{Binding SetLikeCommand}" /> 
      </i:EventTrigger> 
     </i:Interaction.Triggers> 
    </Image> 
</Grid> 

後面的代碼:

using System.Windows; 
using System.Windows.Input; 
using GalaSoft.MvvmLight.Command; 
using Microsoft.Phone.Controls; 

public partial class View : PhoneApplicationPage 
{ 
    public View() 
    { 
     InitializeComponent(); 

     this.DataContext = new MyViewModel(); 
    } 
} 

public class MyViewModel 
{ 
    private ICommand setLike; 

    public ICommand SetLikeCommand 
    { 
     get 
     { 
      return this.setLike ?? (this.setLike = new RelayCommand(this.SetLike)); 
     } 
    } 

    public Visibility LikeVisibility 
    { 
     get 
     { 
      return Visibility.Visible; 
     } 
    } 

    private void SetLike() 
    { 
     var t = "fsdf"; 
    } 
} 
相關問題