ms中的GestureRecognizers获取CommandP

ms中的GestureRecognizers获取CommandP

本文介绍了从Xamarin froms中的GestureRecognizers获取CommandParameter值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将CommandParameter发送到TapGestureRecognizer,并且在我的OnTapGestureRecognizerTapped函数的对象参数中可用.但是我无法从中提取价值.我该如何解决?

I'm sending CommandParameter to TapGestureRecognizer, and it was available in object parameter of my OnTapGestureRecognizerTapped function. But I'm unable to extract value from it. How can I fix this?

我的列表视图(XAML标记):

My list view (XAML markup):

<ListView x:Name="listViewEvents" RowHeight="120" HasUnevenRows="True">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Grid Padding="5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="40"></RowDefinition>
                        <RowDefinition Height="60"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                        <ColumnDefinition Width="90"></ColumnDefinition>
                    </Grid.ColumnDefinitions>

                    <Label Grid.Row="0" Grid.Column="0" FontSize="Large" Grid.ColumnSpan="2"  Text="{Binding UploadTitle}" LineBreakMode="TailTruncation"></Label>
                    <Label Grid.Row="1" Grid.Column="0" Text="{Binding UploadDescription}" Font="Small"  TextColor="Gray" LineBreakMode="TailTruncation"></Label>
                    <Image Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Source="{Binding AttachPath}" Aspect="AspectFill">
                        <Image.GestureRecognizers>
                            <TapGestureRecognizer
                                Tapped="OnTapGestureRecognizerTapped"
                                NumberOfTapsRequired="2"
                                CommandParameter="{Binding AttachPath_New}"
                                />
                        </Image.GestureRecognizers>
                    </Image>
                    <Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding FileName}" LineBreakMode="TailTruncation"></Label>
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

我的C#页面:

void OnTapGestureRecognizerTapped(object sender, EventArgs args)
{
        string fullPath = "";
        Image imageSender = (Image)sender;

        if (imageSender.GestureRecognizers.Count > 0)
        {
            fullPath = imageSender.GestureRecognizers[0].ToString();
        }
        DownloadFile(imageSender.Source.GetValue(UriImageSource.UriProperty).ToString());
}

我在这里得到我的价值:

Here I'm getting my value:

推荐答案

您正在尝试将整个GestureRecognizer转换为字符串,而不仅仅是其CommandParameter属性.

You are trying to convert the entire GestureRecognizer to a string, not just its CommandParameter property.

    void OnTapGestureRecognizerTapped(object sender, EventArgs args)
    {
        string fullPath = "";
        Image imageSender = (Image)sender;
        if (imageSender.GestureRecognizers.Count > 0)
        {
            var gesture = (TapGestureRecognizer)imageSender.GestureRecognizers[0];
            fullPath = (string)gesture.CommandParameter;
        }
        DownloadFile(imageSender.Source.GetValue(UriImageSource.UriProperty).ToString());
    }

这篇关于从Xamarin froms中的GestureRecognizers获取CommandParameter值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:22