Windows.ApplicationModel Namespace
Provides types that represent the core concepts of a Universal Windows Platform (UWP) application, such as the app's lifecycle, packages, and resources.
Overview
The Windows.ApplicationModel namespace is fundamental to UWP development. It allows you to interact with the operating system's understanding of your application.
Key Classes and Interfaces
Package
Represents a UWP app package. Provides access to information like the package family name, version, and installation location.
Members:
string InstallLocation { get; }PackageId Id { get; }StorageFolder InstalledLocation { get; }bool IsDevelopmentMode { get; }
Example:
var package = Package.Current;
var version = package.Id.Version;
Debug.WriteLine($"App version: {version.Major}.{version.Minor}.{version.Build}.{version.Revision}");
PackageId
Represents the unique identifier for a UWP app package.
Members:
string Architecture { get; }string FamilyName { get; }PackageVersion Version { get; }
PackageVersion
Represents the version of a UWP app package.
Members:
ushort Major { get; }ushort Minor { get; }ushort Build { get; }ushort Revision { get; }
AppDisplayInfo
Provides information about the display attributes of an app, such as its logo, display name, and publisher display name.
Members:
string DisplayName { get; }Uri Logo { get; }
ActivationKind
Specifies the kind of activation for an app.
Members:
LaunchProtocolFileStartupTaskSharedStorageAccess
Common Scenarios
Getting App Information
Accessing basic information about the currently running application is a common task.
var appDisplayName = Package.Current.Id.Name;
var appVersion = $"{Package.Current.Id.Version.Major}.{Package.Current.Id.Version.Minor}";
System.Diagnostics.Debug.WriteLine($"Running: {appDisplayName} version {appVersion}");
Accessing App Resources
The InstalledLocation property of the Package class provides access to the app's installation folder, allowing you to retrieve resource files.
async void LoadResourceFile()
{
StorageFolder installedFolder = Package.Current.InstalledLocation;
StorageFile resourceFile = await installedFolder.GetFileAsync("mydata.json");
string fileContent = await FileIO.ReadTextAsync(resourceFile);
// Process fileContent
}