【发布时间】: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 });
}
}
}
}
【问题讨论】:
-
这段代码有什么问题?您在使用此代码时遇到什么问题?
-
Windows 上 .Net 的解决方案是否不适用于 Xamarin?见Reading embedded XML file c# 和How to read embedded resource text file。
标签: c# xml visual-studio xamarin cross-platform