StoreContext Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.
public ref class StoreContext sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Services.Store.StoreContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class StoreContext final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Services.Store.StoreContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class StoreContext
Public NotInheritable Class StoreContext
- Inheritance
- Attributes
Windows requirements
Device family |
Windows 10 Anniversary Edition (introduced in 10.0.14393.0)
|
API contract |
Windows.Services.Store.StoreContract (introduced in v1.0)
|
Remarks
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.
Version history
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 |
Properties
CanSilentlyDownloadStorePackageUpdates |
Gets a value that indicates whether package updates for the current app can be downloaded without displaying a notification UI to the user. |
User |
Gets info about the user that is associated with the current StoreContext object in a multi-user app. |
Methods
AcquireStoreLicenseForOptionalPackageAsync(Package) |
Acquires a license for the specified downloadable content (DLC) add-on package for the current app. |
CanAcquireStoreLicenseAsync(String) |
Gets a value that indicates whether a license can be acquired for the specified downloadable content (DLC) add-on of the current app for the current user. |
CanAcquireStoreLicenseForOptionalPackageAsync(Package) |
Gets a value that indicates whether a license can be acquired for the specified downloadable content (DLC) package of the current app for the current user. |
DownloadAndInstallStorePackagesAsync(IIterable<String>) |
Downloads and installs the specified downloadable content (DLC) packages for the current app from the Microsoft Store without displaying a notification UI dialog to the user. |
FindStoreProductForPackageAsync(IIterable<String>, Package) |
Gets Store product details for the app or add-on that is associated with the specified package. |
GetAppAndOptionalStorePackageUpdatesAsync() |
Gets the collection of packages for the current app that have updates available for download from the Microsoft Store, including optional packages for the app. |
GetAppLicenseAsync() |
Gets license info for the current app, including licenses for add-ons for the current app. |
GetAssociatedStoreProductsAsync(IIterable<String>) |
Gets Microsoft Store listing info for the products that can be purchased from within the current app. |
GetAssociatedStoreProductsByInAppOfferTokenAsync(IIterable<String>) | |
GetAssociatedStoreProductsWithPagingAsync(IIterable<String>, UInt32) |
Gets Microsoft Store listing info for the products that can be purchased from within the current app. This method supports paging to return the results. |
GetAssociatedStoreQueueItemsAsync() |
Gets info about all the new or updated packages that are in the download and installation queue for the current app. |
GetConsumableBalanceRemainingAsync(String) |
Gets the remaining balance for the specified consumable add-on for the current app. |
GetCustomerCollectionsIdAsync(String, String) |
Retrieves a Microsoft Store ID key that can be used to query for product entitlements or to consume product entitlements that are owned by the current user. |
GetCustomerPurchaseIdAsync(String, String) |
Retrieves a Microsoft Store ID key that can be used to grant entitlements for free products on behalf of the current user. |
GetDefault() |
Gets a StoreContext object that can be used to access and manage Microsoft Store-related data for the current user in the context of the current app. |
GetForUser(User) |
Gets a StoreContext object that can be used to access and manage Microsoft Store-related data for the specified user in the context of the current app. |
GetStoreProductForCurrentAppAsync() |
Gets Microsoft Store listing info for the current app and provides access to a method that you can use to purchase the app for the current user. |
GetStoreProductsAsync(IIterable<String>, IIterable<String>, StoreProductOptions) |
Gets Microsoft Store listing info for the specified products that are associated with the current app, with the option to use a filter for the query. |
GetStoreProductsAsync(IIterable<String>, IIterable<String>) |
Gets Microsoft Store listing info for the specified products that are associated with the current app. |
GetStoreQueueItemsAsync(IIterable<String>) |
Gets info about the specified new or updated packages that are in the download and installation queue for the current app. |
GetUserCollectionAsync(IIterable<String>) |
Gets Microsoft Store info for the add-ons of the current app for which the user has purchased. |
GetUserCollectionWithPagingAsync(IIterable<String>, UInt32) |
Gets Microsoft Store info for the add-ons of the current app for which the user has purchased. This method supports paging to return the results. |
GetUserPurchaseHistoryAsync(IIterable<String>) | |
ReportConsumableFulfillmentAsync(String, UInt32, Guid) |
Reports a consumable add-on for the current app as fulfilled in the Microsoft Store. |
RequestDownloadAndInstallStorePackagesAsync(IIterable<String>, StorePackageInstallOptions) |
Attempts to download and install the specified downloadable content (DLC) packages for the current app from the Microsoft Store, with the specified install options. This method also displays a UI dialog that requests permission for the operation. Important This method must be called on the UI thread. |
RequestDownloadAndInstallStorePackagesAsync(IIterable<String>) |
Attempts to download and install the specified downloadable content (DLC) packages for the current app from the Microsoft Store. This method also displays a UI dialog that requests permission for the operation. Important This method must be called on the UI thread. |
RequestDownloadAndInstallStorePackageUpdatesAsync(IIterable<StorePackageUpdate>) |
Attempts to download and install the specified package updates for the current app from the Microsoft Store. This method also displays a UI dialog that requests permission for the operation. Important This method must be called on the UI thread. |
RequestDownloadStorePackageUpdatesAsync(IIterable<StorePackageUpdate>) |
Attempts to download the specified package updates for the current app from the Microsoft Store. This method also displays a UI dialog that requests permission for the operation. Important This method must be called on the UI thread. |
RequestPurchaseAsync(String, StorePurchaseProperties) |
Requests the purchase for the specified app or add-on and displays the UI that is used to complete the transaction via the Microsoft Store. This method provides the option to specify additional details for a specific offer within a large catalog of products that are represented by a single listing in the Microsoft Store, including the product name to display to the user during the purchase. Important This method must be called on the UI thread. |
RequestPurchaseAsync(String) |
Requests the purchase for the specified app or add-on and displays the UI that is used to complete the transaction via the Microsoft Store. Important This method must be called on the UI thread. |
RequestPurchaseByInAppOfferTokenAsync(String) | |
RequestRateAndReviewAppAsync() |
Requests the user to rate and review the app. This method will display the UI for the user to select a Store rating and add an optional Store review for the product. Important This method must be called on the UI thread. |
RequestUninstallStorePackageAsync(Package) |
Attempts to uninstall the specified optional package for the current app. This method also displays a UI dialog that requests permission for the operation. |
RequestUninstallStorePackageByStoreIdAsync(String) |
Attempts to uninstall the specified downloadable content (DLC) package for the current app. This method also displays a UI dialog that requests permission for the operation. |
SetInstallOrderForAssociatedStoreQueueItemsAsync(IIterable<StoreQueueItem>) |
Sets the order in which to install the specified packages in the download and installation queue for the current app. |
TrySilentDownloadAndInstallStorePackageUpdatesAsync(IIterable<StorePackageUpdate>) |
Attempts to download and install the specified package updates for the current app from the Microsoft Store without displaying a notification UI to the user. |
TrySilentDownloadStorePackageUpdatesAsync(IIterable<StorePackageUpdate>) |
Attempts to download the specified package updates for the current app from the Microsoft Store without displaying a notification UI to the user. |
UninstallStorePackageAsync(Package) |
Uninstalls the specified optional package for the current app without displaying a notification UI dialog to the user. |
UninstallStorePackageByStoreIdAsync(String) |
Uninstalls the specified downloadable content (DLC) package for the current app without displaying a notification UI dialog to the user. |
Events
OfflineLicensesChanged |
Raised when the status of the app's license changes (for example, the trial period has expired or the user has purchased the full version of the app). |