Monetizing Windows 8 apps: examples from my book

If you are looking for code examples for Professional Windows 8 Programming: Application Development with C# and XAML book, specifically for the monetization section, you can get them directly from Wiley:

Chapter 11 code for Pro Windows 8 Programming
563.02 KB
Click to Download

What I’ve done in that example is helping you put all monetization techniques together: from unlocking the trial, to using in-app purchase. There’re some neat ideas implemented with the example, for example I use an MVVM model to wrap store licensing schema.

I recommend reading the book first, about the ideas implemented here. This snippet illustrates the first technique of using an MVVM model to wrap the store objects. This may be necessary if you need to expose them later through data binding.

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CatalogShoppingAppCS.Data;
using Windows.ApplicationModel.Core;
using Windows.ApplicationModel.Store;
using Windows.Foundation;
using Windows.UI.Core;

namespace CatalogShoppingAppCS
{
    public class AppLicenseDataModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private bool _licensed = false;
        private string _price;

        public AppLicenseDataModel()
        {
            if (CurrentAppSimulator.LicenseInformation.IsTrial)
            {
                CurrentAppSimulator.LicenseInformation.LicenseChanged += OnLicenseChanged;
                GetListingInformationAsync();
            }
            else
                _licensed = true;
        }

        private async void GetListingInformationAsync()
        {
            var listing = await CurrentAppSimulator.LoadListingInformationAsync();
            _price = listing.FormattedPrice;
        }

        private async void OnLicenseChanged()
        {
            if (!CurrentAppSimulator.LicenseInformation.IsTrial)
            {
                _licensed = true;
                CurrentAppSimulator.LicenseInformation.LicenseChanged -= OnLicenseChanged;

                // need this to the license change occurs on a different thread
                // to update UI bound elements from the data model
                CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    if (IsLicensed)
                    {
                        var groups = CatalogDataModel.GetGroups("AllGroups");
                        foreach (var group in groups)
                            foreach (var item in group.Items)
                                item.IsAdDisplayed = false;
                    }

                    if (PropertyChanged != null)
                    {
                        PropertyChanged(this, new PropertyChangedEventArgs(String.Empty));
                    }
                });
            }
        }

        public bool IsLicensed
        {
            get { return _licensed; }
        }

        public bool IsTrial
        {
            get { return !_licensed; }
        }

        public string LicenseInfo
        {
            get
            {
                if (!_licensed)
                    return "Trial Version";
                else
                    return ("Valid until " + CurrentAppSimulator.LicenseInformation.ExpirationDate.LocalDateTime.ToString("dddd, MMMM d, yyyy"));
            }
        }

        public string FormattedPrice
        {
            get
            {
                if (!String.IsNullOrEmpty(_price))
                    return "Upgrade to the full version for " + _price;
                else
                    return "Upgrade to the full Version";
            }
        }
    }
}

Professional Windows 8 Programming: Application Development with C# and XAML

My apps included with Windows 8 Release Preview

My apps included with Windows 8 Release Preview Store

What a day! Windows 8 Release Preview is released today! And after weekends and nights of coding, my modest contribution to all that Windows glory is now available for your gaming pleasure! The app is called “Card Games Chest” and you can download it from the Store, on any Windows 8 Release Preview tablet, or PC, so go get it now! It’s free as in beer.

Continue reading “My apps included with Windows 8 Release Preview”

Re-imagining app development: Introducing Windows 8 at Microsoft Silicon Valley campus, April 4th

clip_image001[3]

Are you interested in experiencing the next great app platform opportunity, Windows 8? Do you want to learn how to get started building apps for this new platform?

We are inviting the Silicon Valley startup community to a full-day, knockout, deep dive event taking place on our Silicon Valley Campus. Developers and designers alike will take the stage to show you how to take advantage of this new platform opportunity. Several startups will demo their brand new apps and talk about their early experiences developing for Windows 8, while the Microsoft team will provide attendees the opportunity to play with the platform and the tools needed to get started. Sessions will cover designing for the new Metro UI, building for the platform, and monetizing your apps.

Continue reading “Re-imagining app development: Introducing Windows 8 at Microsoft Silicon Valley campus, April 4th”