首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何编写StackLayout命令

如何编写StackLayout命令
EN

Stack Overflow用户
提问于 2018-07-05 07:44:24
回答 3查看 1.7K关注 0票数 0

在我的项目中,我使用了XamEffects包引用在这里输入链接描述

代码语言:javascript
复制
<StackLayout effect:Commands.Tap="{Binding OnTapped}" Grid.Row="1" Grid.ColumnSpan="3" Orientation="Horizontal" effect:TouchEffect.Color="Gray" effect:EffectsConfig.ChildrenInputTransparent="True">
    <Image Source="ic_cont_downtick.png" HeightRequest="25" WidthRequest="25"/>
        <StackLayout Orientation="Vertical" WidthRequest="250" Spacing="0" Margin="10,0,0,0" VerticalOptions="Center">
            <Label Text="Downloaded Content" VerticalOptions="Center" TextColor="Black"/>
            <Label BackgroundColor="#455EEC" HorizontalOptions="Start" VerticalOptions="Start" WidthRequest="20" HeightRequest="4"/>
        </StackLayout>
    <Image Source="ic_rightarrow_1.png" HeightRequest="10" WidthRequest="10" VerticalOptions="Center" HorizontalOptions="End"/>
</StackLayout>

单击stackLayout时,必须导航另一个页面。但是TapGestureRecognizer不能处理这个包。只有指挥部才能起作用。

所以请帮帮我。问候

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-07-05 09:36:21

下面是ViewModel类中绑定的代码

代码语言:javascript
复制
private Command onTapped;
private const string OnTappedCommandPropertyName = "OnTapped";

public Command OnTapped
{
    get
    {
        return onTapped ?? (onTapped = new Command(ExecuteOnTappedCommand));
    }
}

public void ExecuteOnTappedCommand()
{
    //your code here
}

希望能帮上忙!

票数 1
EN

Stack Overflow用户

发布于 2018-07-05 08:13:19

我认为不需要使用xamarin表单中的任何包来做到这一点,您所需要做的就是

代码语言:javascript
复制
<StackLayout>
    <StackLayout.GestureRecognizers>
        <TapGestureRecognizer Command="{Binding tryit}"/>

    </StackLayout.GestureRecognizers>
    <Label Text="hello touch me"/>
</StackLayout>
票数 2
EN

Stack Overflow用户

发布于 2018-08-27 21:46:03

我在自述中指定,您不能使用具有我的效果的手势:

重要:如果您需要一些具有触摸效果的手势,请不要使用GestureRecognizer,而是使用命令,因为Xamarin.Forms中的标准手势不能正常工作。

请在您的控件中使用命令

代码语言:javascript
复制
effect:TouchEffect.Color="Gray" 
effect:Commands.Tap="{Binding TapCommand}"
effect:EffectsConfig.ChildrenInputTransparent="True"

在ViewModel中创建ICommand:

代码语言:javascript
复制
private ICommand _tapCommand;
public ICommand TapCommand => _tapCommand ?? (_tapCommand = new Command(TapExecute));

private void TapExecute()
{
   //something
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51185836

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档