c# - 如何从解决方案中的文件加载 XML 文件,使用嵌入式资源构建?项目 > 跨平台 > Xamarin.Forms
问题描述
如何从解决方案中的文件加载 XML 文件,使用嵌入式资源构建?跨平台 (Xamarin.Forms) - VS
XDocument xDoc = XDocument.Load("Data.xml");
这是我的解决方案的概要: 这是我的解决方案的概要。图像
整页代码:
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 });
}
}
}
}
解决方案
如果你想要一个交叉嵌入的资源,你应该在一个共享或 PCL 项目中放置一个文件。
推荐阅读
- bash - 匹配不包含特定模式的行并在最后附加字符串 - Bash
- cypress - 如何在 Cypress 中正确使用 .wrap()
- python-3.x - 如何在一维中变形/缩放 3 维 numpy 数组?
- python - 403 禁止 - cloud_storage_bucket get_media
- bower - 如何创建自己的凉亭资产?
- django - 如何使用 CreateView 过滤表单字段之一中的查询集值?
- java - 如何在 Java Swing 中制作 JTabbedPane 的圆角
- flutter - Flutter中FlareController的使用
- angular - Angular 反应式验证
- angular - 尝试从模态接收用户选择并传递给 CanDeactivate 时陷入无限循环