Xamarin Forms, How can i send the items from a ListView by email

Amasu 96 Reputation points
2021-01-21T20:24:44.517+00:00

Hi Xamarin Community,

I need help with something I am wondering around, how can I send pdf file using Xamarin forms, but in the file I need to bind the items in my listview like description, price, quantity,

Hope you can help me

Regards

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,336 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,842 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Karen Payne MVP 35,401 Reputation points
    2021-01-21T22:29:43.253+00:00

    Not sure where you are having issues, for the listview aspect look at the bottom of this page. For email see the following and note the platform differences.

    0 comments No comments

  2. Michael Mathias Hachen 81 Reputation points
    2021-01-22T05:38:39.89+00:00

    If you need to create a pdf you could use something like Syncfusion PDF Library. They have a community license.

    0 comments No comments

  3. JarvanZhang 23,951 Reputation points
    2021-01-22T05:46:56.55+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    I am wondering around, how can I send pdf file using Xamarin forms, but in the file I need to bind the items in my listview like description, price, quantity

    @Amasu For this function, try to use the Xamarin.Essentials.Email api to send the email and set the pdf file as the attachment. And you could detect the ItemSelected event of the listView to get the binding data of the item, then pass the data when sending the email.

    Check the code:

       public partial class Page1 : ContentPage  
       {  
           CustomModel model;  
           ...  
           private void Listview_ItemSelected(object sender, SelectedItemChangedEventArgs e)  
           {  
               model = e.SelectedItem as CustomModel;  
           }  
         
           void SendEmail()  
           {  
               var message = new EmailMessage  
               {  
                   Subject = "Hello",  
                   Body = model.Content,//you could pass the content that get from the listview's item  
               };  
         
               var file = xxx;// get the pdf file  
               message.Attachments.Add(new EmailAttachment(file));//send the file as attachment  
         
               await Email.ComposeAsync(message);  
           }  
       }  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  4. Selva Ganapathy K 1 Reputation point
    2021-01-30T07:03:28.663+00:00

    Hi,

    You can achieve your requirement with Syncfusion ListView, Please find the example here.

    In the example:

    1. Loaded a simple SfListView with ten items.
    2. In a button click exported the list view items into a pdf file
    3. In the same button click after the pdf creation is complete it will open the default mail app with the newly created pdf file as an attachment.
    4. In UWP permissions has to be provided.
    5. In Android storage permission has to be enabled to the app in the app's settings.

    Note: I work for Syncfusion

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.