Windows Phone 8中图像的不工作点击事件
本文关键字:工作 事件 Phone 图像 Windows | 更新日期: 2023-09-27 18:21:24
我使用MVVM,并查看下一个代码:
<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>
视图中模型:
private RelayCommand setLike;
public ICommand SetLikeCommand
{
get
{
return this.setLike ?? (this.setLike = new RelayCommand(this.SetLike));
}
}
private void SetLike()
{
var t = "fsdf";
}
当我在方法SetLike()中放入断点时,当我点击图像时,程序不会停止。也许我做错了什么,在哪里绑定事件?请帮忙!
您显示的代码中没有任何根本错误,只是显示的内容不足以识别您的问题。
以下内容确实有效:
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";
}
}