簡體   English   中英

如何從解決方案中的文件加載XML文件,並使用嵌入式資源進行構建? 項目>跨平台> Xamarin.Forms

[英]How to load an XML file from a file in the solution, build with Embedded Resource? Project > Cross Platform > 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項目中。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM