activities/Activities/AboutPage.xaml.cs

80 строки
3.1 KiB
C#

/*
Copyright (c) 2015 Microsoft
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
using System;
using System.IO;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.Storage;
using System.Xml;
using System.Xml.Linq;
/// <summary>
/// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556
/// </summary>
namespace ActivitiesExample
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class AboutPage : Page
{
/// <summary>
/// Constructor
/// </summary>
public AboutPage()
{
this.InitializeComponent();
Loaded += AboutPage_Loaded;
}
/// <summary>
/// Loaded event raised after the component is initialized
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">Event arguments</param>
async void AboutPage_Loaded(object sender, RoutedEventArgs e)
{
string version = "";
var uri = new System.Uri("ms-appx:///AppxManifest.xml");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);
using (var rastream = await file.OpenReadAsync())
using (var appManifestStream = rastream.AsStreamForRead())
{
using (var reader = XmlReader.Create(appManifestStream, new XmlReaderSettings { IgnoreWhitespace = true, IgnoreComments = true }))
{
var doc = XDocument.Load(reader);
var app = doc.Descendants(doc.Root.Name.Namespace + "Identity").FirstOrDefault();
if (app != null)
{
var versionAttribute = app.Attribute("Version");
if (versionAttribute != null)
{
version = versionAttribute.Value;
}
}
}
}
VersionNumber.Text = version;
}
}
}