英文:
Add clicked on HorizontalStackLayout in .NET MAUI
问题
我正在使用.NET MAUI框架制作一个应用程序。
对于按钮,可以添加Clicked
参数来调用一个函数。但我想将其应用于一组元素,如HorizontalStackLayout
或其他不是按钮的元素,比如Label
和Image
。
<ContentPage ...>
<ScrollView>
<VerticalStackLayout>
<HorizontalStackLayout>
<Image Source="assets/profil/EnzoDeg40.png" />
<VerticalStackLayout>
<Label Text="EnzoDeg40"/>
<Label Text="On mange des frites ce soir ?"/>
</VerticalStackLayout>
</HorizontalStackLayout>
...
</VerticalStackLayout>
</ScrollView>
</ContentPage>
英文:
I am making an application with the .net maui framework
With buttons, it is possible to add the Clicked
argument to call a function. But I would like to apply it on a group of elements like HorizontalStackLayout
or other than a button like Label
and Image
.
<ContentPage ...>
<ScrollView>
<VerticalStackLayout>
<HorizontalStackLayout>
<Image Source="assets/profil/EnzoDeg40.png" />
<VerticalStackLayout>
<Label Text="EnzoDeg40"/>
<Label Text="On mange des frites ce soir ?"/>
</VerticalStackLayout>
</HorizontalStackLayout>
...
</VerticalStackLayout>
</ScrollView>
</ContentPage>
答案1
得分: 1
<HorizontalStackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="OnCounterClicked"/>
</HorizontalStackLayout.GestureRecognizers>
正如[Jason](https://stackoverflow.com/users/1338/jason)所述,将[Gesture Recognizer](https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/gestures/tap?view=net-maui-7.0)添加为子元素,允许您向组中添加"OnClick"。
英文:
As Jason mentions, add a Gesture Recognizer as a child allows you to add an "OnClick" to a group
<HorizontalStackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="OnCounterClicked"/>
</HorizontalStackLayout.GestureRecognizers>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论