how to get the selectedItem inside Stackalyout in ListView ?

MrLovaMrLova USMember

Hi Guys,

following senario,

I have a listview with ItemTemplate that is tied to a model, and within Listview I have several stack layouts (text, entrys, ..) and now if I am in an event of entry for example I would like to have my SelectedItem (Model) ,

how can i access the SelectedItem within the textchanged (entry), which in turn is in a listview?

How can I realize this?

thank you in advance

Answers

  • MabroukMabrouk USMember ✭✭✭
    edited November 10

    Hi,

    you can do it like bellow using CommandParameter="{Binding}" :

    1. ListView :

       <ListView
                  x:Name="MessagesListView" 
                  ItemsSource="{Binding Items}" 
                  HasUnevenRows="True"
                  ItemSelected="MessagesListView_ItemSelected" 
                  ItemTapped="MessagesListView_ItemTapped" 
                  SeparatorVisibility="None" >
                  <ListView.ItemTemplate>
                      <DataTemplate>
                          <ViewCell>
                              <Label Text="Click here!">
                                  <Label.GestureRecognizers>
                                      <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" CommandParameter="{Binding}"/>
                                  </Label.GestureRecognizers>
                              </Label>
                          </ViewCell>
                      </DataTemplate>
                  </ListView.ItemTemplate>
              </ListView>
      
    2. Your label Event :

      private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
              {
                  var r = e.Parameter; //Here you will find your data (Model)
              }
      

    I hope that helps,
    Mabrouk.

  • MrLovaMrLova USMember

    hallo Mabrouk,

    thanks a lot for the quick and simple solution.
    it seems to be going in the right direction.
    But I have to click on the label so that the event is resolved. However, i would resolve the event TapGestureRecognizer_Tapped on a entry unfocused event.

    it is possible to fire "TapGestureRecognizer_Tapped "event on entry ?
    Abdou

Sign In or Register to comment.