Mvvm 如何检测listview xamarin表单中的可单击标签位置

Mvvm 如何检测listview xamarin表单中的可单击标签位置,mvvm,xamarin.forms,prism,Mvvm,Xamarin.forms,Prism,我正试着做这样的事情 我有列表视图,点击了标签“编辑”我想要当我点击这个标签时,它的位置被检测并显示出来 单击地址处的标签 我为此使用了TapGestureRecognitor,但当我用谷歌搜索它时,发现所选项目与TapGesture不兼容 这是我的xaml <ListView ItemsSource="{Binding UserAdresses}" SelectedItem="{Binding SelectedAddress}" HorizontalOptions="{Binding

我正试着做这样的事情

我有
列表视图
,点击了
标签
“编辑”我想要当我点击这个标签时,它的位置被检测并显示出来

单击地址处的标签

我为此使用了
TapGestureRecognitor
,但当我用谷歌搜索它时,发现所选项目与TapGesture不兼容

这是我的xaml

<ListView ItemsSource="{Binding UserAdresses}" SelectedItem="{Binding SelectedAddress}" HorizontalOptions="{Binding HoriRLLR}" RowHeight="{Binding RowHeight}" VerticalOptions="FillAndExpand">
                            <ListView.ItemTemplate>
                                <DataTemplate>

                                    <ViewCell>
                                        <StackLayout VerticalOptions="FillAndExpand">
                                            <Label Text="{Binding Country}"  TextColor="Orange" FontSize="Large" FontAttributes="Bold"></Label>

                                            <Label Text="{Binding Address}"  TextColor="Black" FontSize="Medium"></Label>

                                            <Label Text="{Binding City}" TextColor="Black" FontSize="Medium"></Label>

                                            <Label Text="{translator:Translate Edit}" TextColor="Black" FontSize="Medium">

                                                <Label.GestureRecognizers>
                                                    <TapGestureRecognizer
                                                    Command="{Binding Path=BindingContext.EditAddressesCommand,  Source={x:Reference CustomerAdressesPage}}"/>
                                                </Label.GestureRecognizers>
                                                <Label.Effects>
                                                    <controls:UnderlineEffect></controls:UnderlineEffect>
                                                </Label.Effects>

                                            </Label>
                                        </StackLayout>
                                    </ViewCell>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>

我的代码

 public DelegateCommand EditAddressesCommand => new DelegateCommand(EditAddresses); 
        public DelegateCommand DeleteAddressesCommand => new DelegateCommand(DeleteAddresses);
        private readonly IPageDialogService _dialogService;

        private ObservableCollection<CustomerAdressesModel> _userAdresses;
        public ObservableCollection<CustomerAdressesModel> UserAdresses
        {
            get { return _userAdresses; }
            set { SetProperty(ref _userAdresses, value);
            }
        }


        private CustomerAdressesModel _selectedAddress;
        public CustomerAdressesModel SelectedAddress
        {
            get { return _selectedAddress; }
            set { SetProperty(ref _selectedAddress, value); }
        }


        private void EditAddresses()
        {
            _dialogService.DisplayAlertAsync("Test", "Edit Clicked", "Ok");
        }
public DelegateCommand EditAddressesCommand=>new DelegateCommand(EditAddresses);
公共DelegateCommand deleteAddressCommand=>newdelegateCommand(DeleteAddresses);
专用只读IPageDialogService\u dialogService;
私有可观察收集用户地址;
公共可观察收集用户地址
{
获取{return\u useraddress;}
set{SetProperty(ref_useraddress,value);
}
}
私人客户地址模型(您选择的地址);
公共客户地址Model Selected地址
{
获取{return\u selectedAddress;}
set{SetProperty(ref _selectedAddress,value);}
}
私有地址()
{
_dialogService.DisplayAlertAsync(“测试”、“单击编辑”、“确定”);
}

如何执行此操作并检测单击标签的位置

您可以使用以下命令:
CommandParameter=“{Binding.}”
内部
TapgestureRecognitizer

Xaml:


视图模型:

 public ICommand EditAddressesCommand
    {
        get
        {
            return new Command<YourModel>((YourModel model) =>
            {
                //Access your model properties
            });
        }
    }
public ICommand editAddresses命令
{
得到
{
返回新命令((YourModel)=>
{
//访问模型属性
});
}
}

希望这可以解决您的问题。

您可以在
TapGestureRecognitor
内部使用此命令:
CommandParameter=“{Binding.}”

Xaml:


视图模型:

 public ICommand EditAddressesCommand
    {
        get
        {
            return new Command<YourModel>((YourModel model) =>
            {
                //Access your model properties
            });
        }
    }
public ICommand editAddresses命令
{
得到
{
返回新命令((YourModel)=>
{
//访问模型属性
});
}
}

希望这可以解决您的问题。

使用CommandParameter绑定当前对象“.”与我的模型相关还是什么?使用CommandParameter绑定当前对象“.”与我的模型相关还是什么?