Month: February 2013

Portable Class library, MVVM and other pretty things

When developers want to create a navigation architecture on Windows Phone Apps they need to take care about how they want to link the pages with the Business Logic and the Data.

One of the most extended programming methodologies on Windows Phone 8 and Windows 8 is MVVM (Model – View – ViewModel) where you can separate the Entities from the Business Logic (your ViewModel) and the UI (your View).

When I’m developing an app for Windows 8 and Windows Phone 8 what I do is create a Portable Class Library (not available on VS2012 Express version but in higher ones) and write inside my Models and ViewModels adding a reference to my project later on and just implement the Views on the W8 or WP8 project. Here an example:

 

image

 

First to understand what I have inside MyPlayersLibrary:

The Model

image PlayerClass:

I have a simple player class with 3 string properties and is inheriting from BindableBase class. This class will help me to implement the INotifyPropertyChanged interface in every property, just like this:

private string description;
public string PlayerDescription
     {
         get { return description; }
         set { this.SetProperty(ref description, value); }
     }

Once I have the PlayerClass, I can create my collection of Players on my ViewModel, and use this ViewModel as DataContext and the Collection as my ItemsSource for my GridView, ListView or FlipView on Windows 8 or my ListBox or LongListSelector on Windows Phone 8.

The View Model

The second thing to understand is the ViewModel, where I have my collections:

public class PlayersViewModel
{
    private ObservableCollection<Player> barcelonaPlayers = new ObservableCollection<Player>()
    {
           new Player{PlayerName=”Muniesa”, PlayerImage=@”Assets/Players/1.jpg”, PlayerDescription=”Lorem ipsum”},
         new Player{PlayerName=”Abidal”, PlayerImage=@”Assets/Players/2.jpg”,PlayerDescription=”Lorem”},
         new Player{PlayerName=”Adriano”, PlayerImage=@”Assets/Players/3.jpg”,PlayerDescription=”Lorem”},
         new Player{PlayerName=”Alexis”, PlayerImage=@”Assets/Players/4.jpg”,PlayerDescription=”Lore”},
         new Player{PlayerName=”Alves”, PlayerImage=@”Assets/Players/5.jpg”,PlayerDescription=”Lorem”},
         new Player{PlayerName=”Bartra”, PlayerImage=@”Assets/Players/6.jpg”,PlayerDescription=”Lorem “},
         new Player{PlayerName=”Busquets”, PlayerImage=@”Assets/Players/7.jpg”,PlayerDescription=”Lorem”},
         new Player{PlayerName=”Cuenca”, PlayerImage=@”Assets/Players/8.jpg”,PlayerDescription=”Lorem”},
         new Player{PlayerName=”Dos Santos”, PlayerImage=@”Assets/Players/9.jpg”,PlayerDescription=”Lorem”},
         new Player{PlayerName=”Fabregas”, PlayerImage=@”Assets/Players/10.jpg”,PlayerDescription=”Lorem”},
       new Player{PlayerName=”Iniesta”, PlayerImage=@”Assets/Players/11.jpg”,PlayerDescription=”Lorem”},
       new Player{PlayerName=”Jordi Alba”, PlayerImage=@”Assets/Players/12.jpg”,PlayerDescription=”Lorem”},
       new Player{PlayerName=”Mascherano”, PlayerImage=@”Assets/Players/13.jpg”,PlayerDescription=”Lorem”},
       new Player{PlayerName=”Messi”, PlayerImage=@”Assets/Players/14.jpg”,PlayerDescription=”Lorem”},
       new Player{PlayerName=”Montoya”, PlayerImage=@”Assets/Players/15.jpg”,PlayerDescription=”Lorem”},
       new Player{PlayerName=”Pedro”, PlayerImage=@”Assets/Players/16.jpg”,PlayerDescription=”Lorem”},
       new Player{PlayerName=”Pinto”, PlayerImage=@”Assets/Players/17.jpg”,PlayerDescription=”Lore”},
       new Player{PlayerName=”Pique”, PlayerImage=@”Assets/Players/18.jpg”,PlayerDescription=”Lorem”},
       new Player{PlayerName=”Puyol”, PlayerImage=@”Assets/Players/19.jpg”,PlayerDescription=”Lorem”},

    };

    public ObservableCollection<Models.Player> BarcelonaPlayers
    {
        get { return barcelonaPlayers; }
    }
}

The View

My Favorite Players W8 is just a Windows Store project based on XAML, where I’ve defined the main UI with a GridView that is using as DataContext my PlayersViewModel and as ItemsSource the RealMadridPlayers collection I have on my PlayersViewModel.

My Favorite Players Windows Phone 8 project is based on XAML as well and I have a LongListSelector using as DataContext my PlayersViewModel and as ItemsSource the BarcelonaPlayers collection that I have on my PlayersViewModel.

 

image image

 

Just to have this experiences what I have to do is open one of the templates I have on Visual Studio (here I’m using Split Template for W8 and Panorama Template for Windows Phone 8) and perform the next steps:

  1. Add a reference to your portable class library on both projects.
  2. Click on the list (GridView or LongListSelector)
  3. Go to properties and click on new DataContext on the properties tab
  4. Select PlayersViewModel as new DataContext
  5. Go to the properties tab again and click on the small white square that you will see just on the right of the ItemsSource property and in the context menu that will appear select CreateDataBinding, just like this:
image

image

Just to finish the app, what I do is to modify the ItemTemplate for the UIElements on the list:

  1. Right click on the GridView (or LongListSelector on Windows Phone 8)
  2. Select Edit Additional Template –> Edit Item Template –> Edit a copy
  3. Create the copy
  4. Begin binding every element on the template with every property on the Collection Items.

 

Here you can find the complete solution

Interesting links:

Happy coding Smile

Eduardo Ortega – Technical Evangelist
Visit our community Windows8Warriors
Visit our page Windows8Warriors

Making $30,000 a month on Windows 8 apps

 

Developers have been asking me about the revenue you can get from your Windows 8 sales, because now that the product is new, you have a very good opportunity to be on the top apps for many categories, we only have by now not more than 42,400 apps in the store.

First I would like to share with you this story: http://kevinashley.com/making-30000-a-month-on-windows-8-apps/

With less than 100,00 apps on the Windows Store is relatively easy to have your application on the top 10 or top 100 even if you application is a new app, we have seen this behavior with Windows Phone Store (now reaching more than 130,000 apps), so this is the first step, to be able to see the big opportunity that developers has now.

The second is the revenue, you are developing an app and you want to have a Return Of Investment in some way, that is when we have some options:

Revenue Sharing

It starts at 70%, for every new app you publish, for every sale you have you will obtain the 70% of every sale, but (here comes the very good thing), once your app makes $25,000 this range jumps to 80%!!!

So, making 10 M in revenue is not that hard given there are millions of users!

You have to think in the number of users that are using Windows 7 (more than 500M), users that are going to migrate to Windows 8 (as they did it from XP/Vista to Windows 7 time ago). The beginning of Windows 8 has been as good as the beginning of Windows 7(60M Licenses in 3 months is a very good start!) and regarding to the Microsoft Surface Pro, the things are going sooooo good.

In-App Purchases

image

In-App Purchases is very innovative.. You can get purchases that expire over time, for example “renting a book” for a week… or using the Premium subscription of animoto for a week and then going back to the basic subscription…

 

 

Trials

Based on our lessons from Windows Phone, apps with trials get 70x more downloads.. And the conversion rate is pretty high (and quick, usually within hours a few hours ) … at 70x more downloads and a 10% conversion you end up with more revenue..

Your trials can be “Time Limited” and “Feature differentiated”

image 

In your project, the only thin you need to do is enable these lines of code:

 

image

 

And just start enabling or disabling features after the comments on green.

Advertising

You have two options:

  • Microsoft Advertising
  • Your Own

For Microsoft Advertising, first go to http://www.windowsadvertising.com , here you will find a simple API for integrating SDK Support for HTML/XAML.

Get Started in three Easy Steps with Microsoft Advertising SDK for Windows 8

  1. Experiment and learn which ad types, sizes, and experiences are best for your app.

So, repeating one of the most famous phrases of Duke Nukem, “What are you waiting for…Christmas?”

Hunting is opened Smile

 

Eduardo Ortega – Technical Evangelist
Visit our community Windows8Warriors
Visit our page Windows8Warriors