在.NET MAUI中,点击了HorizontalStackLayout。

huangapple go评论105阅读模式
英文:

Add clicked on HorizontalStackLayout in .NET MAUI

问题

我正在使用.NET MAUI框架制作一个应用程序。

对于按钮,可以添加Clicked参数来调用一个函数。但我想将其应用于一组元素,如HorizontalStackLayout或其他不是按钮的元素,比如LabelImage

  1. <ContentPage ...>
  2. <ScrollView>
  3. <VerticalStackLayout>
  4. <HorizontalStackLayout>
  5. <Image Source="assets/profil/EnzoDeg40.png" />
  6. <VerticalStackLayout>
  7. <Label Text="EnzoDeg40"/>
  8. <Label Text="On mange des frites ce soir ?"/>
  9. </VerticalStackLayout>
  10. </HorizontalStackLayout>
  11. ...
  12. </VerticalStackLayout>
  13. </ScrollView>
  14. </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.

  1. &lt;ContentPage ...&gt;
  2. &lt;ScrollView&gt;
  3. &lt;VerticalStackLayout&gt;
  4. &lt;HorizontalStackLayout&gt;
  5. &lt;Image Source=&quot;assets/profil/EnzoDeg40.png&quot; /&gt;
  6. &lt;VerticalStackLayout&gt;
  7. &lt;Label Text=&quot;EnzoDeg40&quot;/&gt;
  8. &lt;Label Text=&quot;On mange des frites ce soir ?&quot;/&gt;
  9. &lt;/VerticalStackLayout&gt;
  10. &lt;/HorizontalStackLayout&gt;
  11. ...
  12. &lt;/VerticalStackLayout&gt;
  13. &lt;/ScrollView&gt;
  14. &lt;/ContentPage&gt;

答案1

得分: 1

  1. &lt;HorizontalStackLayout.GestureRecognizers&gt;
  2. &lt;TapGestureRecognizer Tapped=&quot;OnCounterClicked&quot;/&gt;
  3. &lt;/HorizontalStackLayout.GestureRecognizers&gt;
  1. 正如[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)添加为子元素,允许您向组中添加&quot;OnClick&quot;。
英文:

As Jason mentions, add a Gesture Recognizer as a child allows you to add an "OnClick" to a group

  1. &lt;HorizontalStackLayout.GestureRecognizers&gt;
  2. &lt;TapGestureRecognizer Tapped=&quot;OnCounterClicked&quot;/&gt;
  3. &lt;/HorizontalStackLayout.GestureRecognizers&gt;

huangapple
  • 本文由 发表于 2023年2月16日 05:50:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75465752.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定