UWP 检查是否试用版模式

//老版本的方法:
         // var check=  CurrentAppSimulator.LicenseInformation.IsActive && CurrentAppSimulator.LicenseInformation.IsTrial;
        private StoreContext context = null;
        private StoreAppLicense appLicense = null;

        // Call this while your app is initializing.
        private async void InitializeLicense()
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
                // If your app is a desktop app that uses the Desktop Bridge, you
                // may need additional code to configure the StoreContext object.
                // For more info, see https://aka.ms/storecontext-for-desktop.
            }

            workingProgressRing.IsActive = true;
            appLicense = await context.GetAppLicenseAsync();
            workingProgressRing.IsActive = false;

            // Register for the licenced changed event.
            context.OfflineLicensesChanged += context_OfflineLicensesChanged;

          
            if ( appLicense.IsTrial)
            {
                textBlock.Text = $"This is the trial version. Expiration date: {appLicense.ExpirationDate}";

                // Show the features that are available during trial only.
            }
            else
            {
                // Show the features that are available only with a full license.
            }
        }

        private async void context_OfflineLicensesChanged(StoreContext sender, object args)
        {
            // Reload the license.
            workingProgressRing.IsActive = true;
            appLicense = await context.GetAppLicenseAsync();
            workingProgressRing.IsActive = false;

            if (appLicense.IsActive)
            {
                if (appLicense.IsTrial)
                {
                    textBlock.Text = $"This is the trial version. Expiration date: {appLicense.ExpirationDate}";

                    // Show the features that are available during trial only.
                }
                else
                {
                    // Show the features that are available only with a full license.
                }
            }
        }

  

参考官方:https://docs.microsoft.com/en-us/windows/uwp/monetize/in-app-purchases-and-trials#implement-trial

原文地址:https://www.cnblogs.com/wgscd/p/13683713.html