在.NET MAUI中,点击了HorizontalStackLayout。

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

Add clicked on HorizontalStackLayout in .NET MAUI

问题

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

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

<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.

&lt;ContentPage ...&gt;
    &lt;ScrollView&gt;
        &lt;VerticalStackLayout&gt;
            &lt;HorizontalStackLayout&gt;
                &lt;Image Source=&quot;assets/profil/EnzoDeg40.png&quot; /&gt;
                &lt;VerticalStackLayout&gt;
                    &lt;Label Text=&quot;EnzoDeg40&quot;/&gt;
                    &lt;Label Text=&quot;On mange des frites ce soir ?&quot;/&gt;
                &lt;/VerticalStackLayout&gt;
            &lt;/HorizontalStackLayout&gt;
            ...
        &lt;/VerticalStackLayout&gt;
    &lt;/ScrollView&gt;
&lt;/ContentPage&gt;

答案1

得分: 1

&lt;HorizontalStackLayout.GestureRecognizers&gt;
    &lt;TapGestureRecognizer Tapped=&quot;OnCounterClicked&quot;/&gt;
&lt;/HorizontalStackLayout.GestureRecognizers&gt;
正如[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

&lt;HorizontalStackLayout.GestureRecognizers&gt;
    &lt;TapGestureRecognizer Tapped=&quot;OnCounterClicked&quot;/&gt;
&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:

确定