0

我想知道是否可以通过编程方式找出 Windows Phone 8 中 NavigationPage 的名称?它是 WMAppManifest.xml 文件的一部分,所以我希望它是可能的。

4

1 回答 1

2

好,我知道了!

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

namespace zanoxSDK
{
    public class WMAppManifestReader
    {
        private static WMAppManifestReader instance = null;
        private string navigationPage = string.Empty;

        private WMAppManifestReader()
        {
            this.ReadAppManifest();
        }

        public static WMAppManifestReader GetInstance()
        {
            if (instance == null)
            {
                instance = new WMAppManifestReader();
            }

            return instance;
        }

        private void ReadAppManifest()
        {
            string wmData = string.Empty;
            System.Xml.Linq.XElement appxml = System.Xml.Linq.XElement.Load("WMAppManifest.xml");
            var appElement = (from manifestData in appxml.Descendants("DefaultTask") select manifestData).SingleOrDefault();

            if (appElement != null)
            {
                navigationPage = appElement.Attribute("NavigationPage").Value;
            }

            appElement = (from manifestData in appxml.Descendants("PrimaryToken") select manifestData).SingleOrDefault();
        }

        public string NavigationPage
        {
            get { return this.navigationPage; }
        }
    }
}
于 2013-06-06T12:19:19.190 回答