0

How to load an XML file from a file in the solution, build with Embedded Resource? Cross Platform (Xamarin.Forms) - VS

XDocument xDoc = XDocument.Load("Data.xml");

Here's an outline of my solution: Here's an outline of my solution.IMAGE

Full page code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using System.Xml.Linq;
using Xamarin.Forms.Xaml;

namespace App14
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class ListMain : ContentPage
    {

        public List<string> Students; 

        public ListMain ()
        {

            InitializeComponent ();
            Students = new List<string>(); 
            XDocument xDoc = XDocument.Load("Data.xml");
            foreach (XElement xe in xDoc.Element("students").Elements("mainStudent"))
            {
                Students.Add(xe.Element("student").Value); 
            }

            foreach (string student in Students)
            {
               stackLayout.Children.Add(new Label { Text = student, FontSize = 20, HorizontalOptions = LayoutOptions.StartAndExpand });
               stackLayout.Children.Add(new Label { Text = "DEL", FontSize = 20, HorizontalOptions = LayoutOptions.End });
            }


        }


    }
}
4

1 Answer 1

0

If you want a cross embedded resource, you should place a file inside a shared or PCL project.

https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=vswin#embedded-images

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.