Call the popup from a listview itemtapped event.

I have a listview (xamarin) with data...and i need when click the listview item, call the popup showing another listview with 2 options.
And i have to get what action was clicked on the popup.
But my code are giving me the error "sequence contains no elements". My Xaml Code


    <ContentPage.Content>
        <StackLayout>
            <ListView Margin="10" x:Name="listView" HasUnevenRows="true" BackgroundColor="White" ItemTapped="ListViewTapped">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="Fill" >
                                <StackLayout Padding="10,10,10,0" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
                                    <Label Text="{Binding Marca.NomeMarca}" FontAttributes="Bold" TextColor="DeepSkyBlue" Margin="0" VerticalOptions="Center" HorizontalOptions="Start"/>
                                    <Label Text="{Binding Modelo.NomeModelo, StringFormat='{0}'}" FontAttributes="Bold" TextColor="DeepSkyBlue" Margin="0" VerticalOptions="Center" />
                                    <Label Text="{Binding Tamanho, StringFormat='{0}m'}" VerticalOptions="Center" FontAttributes="Bold" Margin="0" TextColor="DeepSkyBlue"/>
                                    <Label Text="{Binding AnoFab}" FontAttributes="Bold" TextColor="DeepSkyBlue" Margin="0" VerticalOptions="Center" />
                                </StackLayout>
                                <StackLayout  Padding="10,0,10,0" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
                                    <Label  Text="{Binding Usuario.Nome, StringFormat='Nome: {0}'}" TextColor="Black" FontAttributes="Bold" VerticalOptions="Center" />
                                </StackLayout>
                                <StackLayout  Padding="10,0,10,0" Margin="0" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
                                    <Label Text="{Binding Usuario.Email, StringFormat='Email: {0}'}" TextColor="DarkGray" FontAttributes="Bold" Margin="0" VerticalOptions="Center" HorizontalOptions="Start"/>
                                    <Label Text="{Binding Usuario.Telefone, StringFormat='Tel: {0}'}" TextColor="DarkGray" FontAttributes="Bold" Margin="0" VerticalOptions="Center" HorizontalOptions="EndAndExpand"/>
                                </StackLayout>
                                <StackLayout Padding="10,0,10,0" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
                                    <Label  Text="{Binding NumSerie, StringFormat='Nº de série: {0}'}" Margin="0" VerticalOptions="Center" HorizontalOptions="StartAndExpand"/>
                                </StackLayout>
                                <StackLayout Padding="10,0,10,0" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
                                    <Label  Text="{Binding Estado, StringFormat='Local: {0}'}" VerticalOptions="Center" HorizontalOptions="StartAndExpand" />
                                </StackLayout>
                                <StackLayout  Padding="10,0,10,0" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
                                    <Label  Text="{Binding Reparos, StringFormat='Reparos: {0}'}" VerticalOptions="Center" />
                                </StackLayout>
                                <StackLayout  Padding="10,0,10,0" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
                                    <Label Text="{Binding SinalIdentificador, StringFormat='Sinais: {0}'}" VerticalOptions="Center" />
                                </StackLayout>

                            </StackLayout>


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

            </ListView>
        </StackLayout>
        
            <sfPopup:SfPopupLayout x:Name="popupLayout">
                <sfPopup:SfPopupLayout.Content>
                <StackLayout x:Name="mainLayout">
                    <ListView Margin="10" x:Name="popupList" HasUnevenRows="true" BackgroundColor="White">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <ViewCell.View>
                                        <Grid x:Name="grid" RowSpacing="1">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="*" />
                                                <RowDefinition Height="*" />
                                            </Grid.RowDefinitions>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="50" />
                                                <ColumnDefinition Width="200" />
                                            </Grid.ColumnDefinitions>

                                            <Image Grid.Row="0" Grid.Column="0" Source="ic_person_add.png"
                                               VerticalOptions="Center"
                                               HorizontalOptions="Center"
                                               HeightRequest="50"/>

                                            <Label Grid.Row="0" Grid.Column="1"
                                                HorizontalTextAlignment="Center"
                                                LineBreakMode="NoWrap"
                                                Text="Adicionar à agenda telefônica" />

                                            <Image Grid.Row="1" Grid.Column="0" Source="ic_mensagem.png"
                                               VerticalOptions="Center"
                                               HorizontalOptions="Center"
                                               HeightRequest="50"/>

                                            <Label Grid.Row="1" Grid.Column="1"
                                                HorizontalTextAlignment="Center"
                                                LineBreakMode="NoWrap"
                                                Text="Enviar e-mail." />
                                        </Grid>
                                    </ViewCell.View>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>

                    </ListView>
                 </StackLayout>
                </sfPopup:SfPopupLayout.Content>
            </sfPopup:SfPopupLayout>
    </ContentPage.Content>


On itemtappedEvent i call popupLayout.Show(mainLayout);

What i am doing wrong ?

9 Replies

SS Suhasini  Suresh Syncfusion Team April 24, 2018 11:01 PM UTC

Hi Marcelo, 
 
Thanks for contacting Syncfusion Support. 
 
We are not able to reproduce the issue reported. We have prepared a sample to achieve your requirement with the Xamarin.Forms.ListView and tapping the item in the ListView opens the popup which contains another ListView. 
 
However we had an issue in setting the Binding for the child views in popup, we fixed the issue internally and have referred the custom assemblies which includes the fix for the Binding issue in the sample attached. You can use that custom assemblies for your requirement. The fix for the Binding issue will be included in 2018 Volume 2 main release which will be rolled out by the last week of May 2018. 
 
Regarding your query to know what action is clicked in the popup, 
 
 AcceptCommand will be fired, when the accept button is clicked and similarly DeclineCommand will be fired when decline button is clicked. Please find the code snippet for setting the AcceptCommand, DeclineCommand and Popup closing event.  
popupLayout.PopupView.AcceptCommand = new CustomAcceptCommand(); 
popupLayout.PopupView.DeclineCommand = new CustomDeclineCommand(); 
popupLayout.Closing += PopupLayout_Closing; 
 
private void PopupLayout_Closing(object sender, System.ComponentModel.CancelEventArgs e) 
{ 
   // Hits when the popup closes. 
} 
 
// CustomAcceptCommand 
public class CustomAcceptCommand : ICommand 
{ 
    public event EventHandler CanExecuteChanged; 
 
    public bool CanExecute(object parameter) 
    { 
        // Hits when the Accept Button in the popup is clicked 
        return true; 
    } 
 
    public void Execute(object parameter) 
    { 
         
    } 
} 
 
// CustomDeclineCommand 
public class CustomDeclineCommand : ICommand 
{ 
    public event EventHandler CanExecuteChanged; 
 
    public bool CanExecute(object parameter) 
    { 
        // Hits when the Decline Button in the popup is clicked 
        return true; 
    } 
 
    public void Execute(object parameter) 
    { 
 
    } 
} 
 
 
Regards, 
Suhasini  



MC marcelo couto fernandes April 25, 2018 03:05 AM UTC

I am getting System.null.reference when call popupLayout.Show(this.Content);

Why did you Binding Items if the listview collections already has the items ? But is just a question...i tried with and without...didnt work.


SK Suriya Kalidoss Syncfusion Team April 25, 2018 12:50 PM UTC

Hi Marcelo, 
Thanks for your update.  
 
We analyzed your query. We do not find null reference exception from our side and the below attached sample working fine from our side. We had attached working sample and Video for your reference, please download it from below link.  
 
 
Note : Please refer the custom assemblies of SfPopupLayout which is referred to the sample in the above sample link, which contains the fix for the Binding issue in SfPopupLayout. 
 
If the issue still exists from your side, please provide us the following details, in order to provide you the solution faster. 
Properties set to the Popup  
Regarding your query on binding items to the ListView, 
In the attached sample, ItemsSource is binded with the property in the ViewModel for the ListView, which is set inside the popup and the ItemTemplate for it is defined.  
Please refer the below link for more details 
Regards, 
Suriya K 
 



MC marcelo couto fernandes April 25, 2018 06:48 PM UTC

What I need is:

I have a xamarin.forms.listview with their values(ex: User1 info, User2 info, User3 info...). When the user click on the listview item (ex: User1 info), open the Sfpopup with 3 options (Send a message, Add to contacts list, Save to favorites). Identical of This link of your website.
Thats what I need. :)

Thanks.


SS Suhasini  Suresh Syncfusion Team April 26, 2018 11:52 AM UTC

Hi Marcelo,  
 
Thanks for your update.   
 
We have modified the sample as per your requirement, loading a list view with the items “User 1 Info, User 2 Info, ….” and tapping the item in the list view, displays another list view with the items ” Send a message, Add to contacts list, Save to favorites”. You can download the sample from the below link. 
 
 
Regards, 
Suhasini  



MC marcelo couto fernandes April 27, 2018 01:43 AM UTC

I don´t know why, but when i try to use Grid inside of the listview, doesn´t work... broke on popupLayout.Show(this.Content);
If i take off the listview and just use the Grid or just the Listview without the layout (grid), works.
But I would like to do like this example . So, i need to use the Grid inside of the Listview.

Also, i need to get the response of the Popup clicked item...(Ex: send a message)


Look my code attached. 

Please, fix my code if its possible. 


Thanks.

Attachment: Views_3808938f.zip


SS Suhasini  Suresh Syncfusion Team April 30, 2018 04:06 AM UTC

Hi Marcelo,   
  
Thanks for your update.   
 
We checked your query and set the Grid as the ItemTemplate in ListView, we are not getting exception and it is working fine. Please find the sample below in which Grid is set as the ItemTemplate in ListView.  
 
 
If you still get any issue, please revert us with the modified code in the above sample and replication procedure to reproduce the issue, which helps us to provide you the solution faster.  
 
Since, your requirement is to achieve a sample like the link you shared in the previous update, we have shared the code example for the sample in the below link. 
 
 
Regards, 
Suhasini  



MC marcelo couto fernandes May 2, 2018 10:30 PM UTC

Its strange... in your example, the content of this.Content is a Xamarin.Forms.ListView  and works.

In mine, when debug, the this.Content is a Xamarin.Forms.ListView and is not working. When i go into exception, the content of this.Content changes to SyncFusion.XForms.PopupLayout.SfPopupLayoutbecause and the Content inside of this, is Null.


SS Suhasini  Suresh Syncfusion Team May 3, 2018 12:54 PM UTC

Hi Marcelo, 
 
A support incident to track the status of this query has been created under your account. Please log on to our support website to check for further updates:  
 
 
Regards, 
Suhasini  


Loader.
Up arrow icon