-api-id | -api-type |
---|---|
T:Windows.Services.Store.StoreContext |
winrt class |
Provides members you can use to access and manage Microsoft Store-related data for the current app. For example, you can use members of this class to get Microsoft Store listing and license info for the current app, purchase the current app or products that are offered by the app, or download and install package updates for the app.
In a desktop app, before using an instance of this class in a way that displays UI, you'll need to associate the object with its owner's window handle. For more info, and code examples, see Display WinRT UI objects that depend on CoreWindow.
Note
This class and the rest of the Windows.Services.Store namespace was introduced in Windows 10, version 1607. This class can only be used in projects that target Windows 10 Anniversary Edition (10.0; Build 14393) or a later release in Visual Studio. If your project targets an earlier version of Windows 10, you must use the Windows.ApplicationModel.Store namespace instead of the Windows.Services.Store namespace. For more information, see In-app purchases and trials.
The StoreContext class is the main entry point to the Windows.Services.Store namespace. Use members of this class to perform tasks such as getting Microsoft Store listing and license info for the current app, purchasing the current app or add-ons that are offered by the app, or downloading and installing package updates for the app. Other classes and types in this namespace represent items such as add-ons for the app, licenses for the app and its add-ons, and Microsoft Store listing info for the app.
To get a StoreContext object, use one of these static methods:
-
GetDefault: Use this method in single-user apps (that is, apps that run only in the context of the user that launched the app). This method gets a StoreContext object that you can use to access and manage Microsoft Store-related data for the user. Most Universal Windows Platform (UWP) apps are single-user apps.
Windows.Services.Store.StoreContext context = StoreContext.GetDefault();
-
GetForUser: Use this method in multi-user apps. This method gets a StoreContext object that you can use to access and manage Microsoft Store-related data for a specific user. For more information about multi-user apps, see Introduction to multi-user applications.
var users = await Windows.System.User.FindAllAsync(); Windows.Services.Store.StoreContext context = StoreContext.GetForUser(users[0]);
After you have a StoreContext object, you can start calling methods to purchase an app or add-on for the current user and other tasks. For more information, see the following articles:
- In-app purchases and trials
- Get product info for apps and add-ons
- Get license info for apps and add-ons
- Enable in-app purchases of apps and add-ons
- Enable consumable add-on purchases
- Implement a trial version of your app
You can also use a StoreContext object to download and install package updates for the app. For more information, see Download and install package updates for your app.
Windows version | SDK version | Value added |
---|---|---|
1703 | 15063 | FindStoreProductForPackageAsync |
1803 | 17134 | CanAcquireStoreLicenseAsync |
1803 | 17134 | CanAcquireStoreLicenseForOptionalPackageAsync |
1803 | 17134 | CanSilentlyDownloadStorePackageUpdates |
1803 | 17134 | DownloadAndInstallStorePackagesAsync |
1803 | 17134 | GetAssociatedStoreQueueItemsAsync |
1803 | 17134 | GetStoreProductsAsync(IEnumerable<String>,IEnumerable<String>,StoreProductOptions) |
1803 | 17134 | GetStoreQueueItemsAsync |
1803 | 17134 | RequestDownloadAndInstallStorePackagesAsync(IEnumerable<String>,StorePackageInstallOptions) |
1803 | 17134 | RequestUninstallStorePackageAsync |
1803 | 17134 | RequestUninstallStorePackageByStoreIdAsync |
1803 | 17134 | TrySilentDownloadAndInstallStorePackageUpdatesAsync |
1803 | 17134 | TrySilentDownloadStorePackageUpdatesAsync |
1803 | 17134 | UninstallStorePackageAsync |
1803 | 17134 | UninstallStorePackageByStoreIdAsync |
1809 | 17763 | RequestRateAndReviewAppAsync |
1809 | 17763 | SetInstallOrderForAssociatedStoreQueueItemsAsync |
In-app purchases and trials, Download and install package updates for your app, Store sample, Display WinRT UI objects that depend on CoreWindow