Как определить позицию кликабельной метки внутри формы списка xamarin - PullRequest
0 голосов
/ 07 мая 2018

Я пытаюсь сделать что-то подобное

Like This

У меня есть Listview с нажатием label "Изменить". Я хочу, чтобы при нажатии на этот ярлык обнаруживалась его позиция и отображалось

* На ярлыке Aliaddress нажата

Я использовал TapGestureRecognizer для этого, но когда я в Google, я обнаружил, что выбранный элемент не работает с 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");
        }

Как я могу это сделать и определить положение нажатой метки

1 Ответ

0 голосов
/ 07 мая 2018

Вы можете использовать это: CommandParameter="{Binding .}" внутри TapGestureRecognizer

Xaml:

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

ViewModel:

 public ICommand EditAddressesCommand
    {
        get
        {
            return new Command<YourModel>((YourModel model) =>
            {
                //Access your model properties
            });
        }
    }

Надеюсь, что это может решить вашу проблему.

...