【问题标题】:How to load an XML file from a file in the solution, build with Embedded Resource? Project > Cross Platform > Xamarin.Forms如何从解决方案中的文件加载 XML 文件,使用嵌入式资源构建?项目 > 跨平台 > Xamarin.Forms
【发布时间】:2018-10-21 20:09:38
【问题描述】:

如何从解决方案中的文件加载 XML 文件,使用嵌入式资源构建?跨平台 (Xamarin.Forms) - VS

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

这是我的解决方案的概要: Here's an outline of my solution.IMAGE

整页代码:

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 });
            }


        }


    }
}

【问题讨论】:

标签: c# xml visual-studio xamarin cross-platform


【解决方案1】:

如果你想要一个交叉嵌入的资源,你应该在一个共享或 PCL 项目中放置一个文件。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-15
    • 2017-03-11
    相关资源
    最近更新 更多