我是一名有用的助手,可以为您翻译文本。
我有一个关于图像按钮的问题,我希望我的函数“Categorie_Onclick”能够知道哪个按钮被点击了。我尝试过添加标签,但没有成功。有没有什么方法可以做到这一点?
XAML:
我有一个关于图像按钮的问题,我希望我的函数“Categorie_Onclick”能够知道哪个按钮被点击了。我尝试过添加标签,但没有成功。有没有什么方法可以做到这一点?
XAML:
<!-- Button1 -->
<Image
x:Name="CityGuideButton1"
Source="shopping_gray.png"
Aspect="Fill"
HorizontalOptions="FillAndExpand"
VerticalOptions ="FillAndExpand"
Tag="01">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="Categorie_Onclick"
NumberOfTapsRequired="1"/>
</Image.GestureRecognizers>
</Image>
<!-- Button2 -->
<Image
x:Name="CityGuideButton2"
Source="secrets.png"
Aspect="Fill"
HorizontalOptions="FillAndExpand"
VerticalOptions ="FillAndExpand"
Tag="02">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="Categorie_Onclick"
NumberOfTapsRequired="1"/>
</Image.GestureRecognizers>
private async void Categorie_Onclick(Object sender, EventArgs args)
{
Image cmd = sender as Image;
string txt = TapGestureRecognizer.tag.ToString();
await Navigation.PushAsync(new CategoriePage());
}