gpt4 book ai didi

c# - Windows Phone 8 中图像的点击事件不起作用

转载 作者:行者123 更新时间:2023-12-03 10:38:00 25 4
gpt4 key购买 nike

我使用 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>

在 View 模型中:

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


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

当我在方法 SetLike() 中设置断点时,当我点击图像时程序不会停止。也许我在 View 中做错了什么,绑定(bind)事件在哪里?请帮忙!

最佳答案

您显示的代码没有任何根本性的错误,只是不足以识别您的问题。

以下确实有效:

xml:

<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";
}
}

关于c# - Windows Phone 8 中图像的点击事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17506718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com