venerdì 28 giugno 2013

Windows Phone - Caliburn Micro and Telerik

When you use Caliburn Micro you always have a file Bootstrapper like this:

public class Bootstrapper : PhoneBootstrapper
{
 PhoneContainer container;

 protected override void Configure()
 {
  container = new PhoneContainer();
  
  container.RegisterPhoneServices(RootFrame);

  container.PerRequest<MainPageViewModel>();
  
  AddCustomConventions();
 }

 static void AddCustomConventions()
 {
 }

 protected override object GetInstance(Type service, string key)
 {
  return container.GetInstance(service, key);
 }

 protected override IEnumerable<object> GetAllInstances(Type service)
 {
  return container.GetAllInstances(service);
 }

 protected override void BuildUp(object instance)
 {
  container.BuildUp(instance);
 }
}

I love to use Windows Phone controls from Telerik and I always add RadPhoneApplicationFrame in my applications, but how to add it in the Bootstrapper?

You need only some lines of code.


private PhoneApplicationFrame rootFrame;
private new PhoneApplicationFrame RootFrame
{
 get
 {
  if (this.rootFrame == null)
   this.rootFrame = new RadPhoneApplicationFrame();

  return this.rootFrame;
 }
 set
 {
  this.rootFrame = value;
 }
}

protected override PhoneApplicationFrame CreatePhoneApplicationFrame()
{
 return this.RootFrame;
}
  

I created a public property to instantiate the RadPhoneApplicationFrame and overrided the CreatePhoneApplicationFrame to return the custom frame.

Here the new Bootstrapper:

public class Bootstrapper : PhoneBootstrapper
{
 PhoneContainer container;

 private PhoneApplicationFrame rootFrame;

 private new PhoneApplicationFrame RootFrame
 {
  get
  {
   if (this.rootFrame == null)
    this.rootFrame = new RadPhoneApplicationFrame();

   return this.rootFrame;
  }
  set
  {
   this.rootFrame = value;
  }
 }

 protected override void Configure()
 {
  container = new PhoneContainer();
  
  container.RegisterPhoneServices(RootFrame);

  container.PerRequest<MainPageViewModel>();
  
  AddCustomConventions();
 }

 protected override PhoneApplicationFrame CreatePhoneApplicationFrame()
 {
  return this.RootFrame;
 }

 static void AddCustomConventions()
 {
 }

 protected override object GetInstance(Type service, string key)
 {
  return container.GetInstance(service, key);
 }

 protected override IEnumerable<object> GetAllInstances(Type service)
 {
  return container.GetAllInstances(service);
 }

 protected override void BuildUp(object instance)
 {
  container.BuildUp(instance);
 }
}

domenica 16 giugno 2013

Coding4Fun - ThemedImageConverter

When you publish an application, you need to meet the requirement 5.5.2 from Dev Center:
"App content, such as text and visual elements, must be visible and legible regardless of the phone theme without panning horizontally or zooming.."

The example is when you have an image with the same color of background theme.
What you can do?
- select a different color for image.
- manage the image source swap from code behind.
- the best practice is to use the ThemedImageConverter from Coding4Fun Toolkit.

Let's go:
Download the Coding4Fun Toolkit from NuGet or Codeplex.

Add the static resource in your page:
<c4fun:themedimageconverter x:key="ThemedImageConverter"></c4fun:themedimageconverter>

Use this simple converter in your image:
<Image Source="{Binding Converter={StaticResource ThemedImageConverter}, ConverterParameter={StaticResource PhoneBackgroundColor}}" DataContext="/Assets/{0}/img.png" />

You can check also the InverseThemedImageConverter to swap from light and dark themes.


domenica 21 aprile 2013

Windows Phone 7.8 - Gmail Sync: contacts and calendar

After January 30 2013, Google dropped Exchange ActiveSync support.
Now if you add a Google account in Windows Phone 7.8, you can sync only emails.
But if I want to sync my Google Contacts and Calendars...??

Just follow this steps:
- Go in Settings >>> Email + Accounts.
- Add an account.
- Choose Outlook (Outlook.com, Exchange, Office 365).
- Write you Google email, password and press Sign In button.

Fill the new page with this informations:
- Account: your Google email
- Domain: google
- Server: m.google.com

Et voilà, you done! :)



martedì 19 marzo 2013

Vote myMoneyBook and win a Lumia 920


Microsoft is running a campaign called Windows Phone Next App Star, and guess what? Over 9,000 apps entered the competition, and my app myMoneyBook is one of 64 finalists!

Starting today, March 19, my app is in a head-to-head battle with another finalist. If my app gets the most votes, it keeps moving forward, and I keep winning more prizes.  If my app wins the whole thing, myMoneyBook will be Windows Phone Next App Star and will be featured in an upcoming Windows Phone television ad!

Even better, every time people like you participate in the campaign and vote, they are entered to win a brand new Lumia 920 Windows Phone! Microsoft is giving away one Lumia 920 every day throughout the contest, and every vote is an entry.
Will you please help me become Windows Phone Next App Star?


Please note:
you may have to vote several times before reaching the voting opportunity for my app. There are 32 first round match-ups, just look for a picture of me and my app myMoneyBook.




martedì 19 febbraio 2013

PeriodicTask bug in Windows Phone 8


After almost two months, WPDev Team has confirmed a bug for PeriodicTask in Windows Phone 8:

PeriodicTask fails to trigger if there is no network connectivity in WP8 (enable Airplane mode,  or disable both cellular and wifi.

Here my discussion: http://social.msdn.microsoft.com/Forums/en-US/wpdevelop/thread/216a9f3d-9284-4d1e-ac2a-83f2d13e361c


mercoledì 6 febbraio 2013

Easy SQL CE on Windows Phone

In Windows Phone is very simple to add and use SQL CE database.
What you need? Nothing... it's built in the Windows Phone Runtime.

Let's start...

If not exists, add the reference System.Data.Linq in your project.

Create the class to map the entity to the table:
[Table(Name="Utenti")]
public class Utente
{
    [Column(IsPrimaryKey = true, IsDbGenerated = true)]
    public int Id { get; set; }

    [Column(CanBeNull = false)]
    public string Name { get; set; }
}
You can see the attributes for the table and columns: table name, primary key, etc..

Now add a class for DataContext with the reference to the table Utenti. The DataContext wraps all operations you can do with database:
public class MyDataContext: DataContext
{
    public const string ConnectionString = "isostore:/mydatabase.sdf";

    public Table<Utente> Utenti { get; set; }

    public MyDataContext(string connectionString)
        : base(connectionString)
    {
        this.Utenti = this.GetTable<Utente>();
    }
}
ConnectionString has the special path to locate the database file in the isolated storage.

The classes for SQL CE are ready.
The last thing is create the physical .sdf file when the application start.
private void Application_Launching(object sender, LaunchingEventArgs e)
{    
    using (var context = new MyDataContext(MyDataContext.ConnectionString))
    {
        if (!context.DatabaseExists())
            context.CreateDatabase();
    }
}

And now enjoy with your LinqToSql queries!
using (var context = new MyDataContext(MyDataContext.ConnectionString))
{
    var utenti = context.Utenti.OrderByDescending(u => u.Name).ToList();
}

Remember the "using" statement, because you need to dispose your DataContext to prevent high memory usage. The cost to create a new istance is very small.

NOTE: if you want to build an application for Windows 8/RT, maybe SQL CE is not your way. Why? Unfortunately Windows 8/RT don't support it. In this case you can use SQLITE.

venerdì 18 gennaio 2013

Windows Phone 8 - Theme Colors (HEX - RGB)

Do you want to know the HEX or the RGB of Windows Phone 8 theme colors? Here the table. Just copy/paste the code below:

Lime: #A4C400 Green: #60A917 Emerald: #008A00 Teal: #00ABA9 Cyan: #1BA1E2
Cobalt: #0050EF Indigo: #6A00FF Violet: #AA00FF Pink: #F472D0 Magenta: #D80073
Crimson: #A20025 Red: #E51400 Orange: #FA6800 Amber: #F0A30A Yellow: #E3C800
Brown: #825A2C Olive: #6D8764 Steel: #647687 Mauve: #76608A Taupe: #87794E


Complete list with RGB:
  • Lime: #A4C400; RGB(164, 196, 0)
  • Green: #60A917; RGB(96, 169, 23)
  • Emerald: #008A00; RGB(0, 138, 0)
  • Teal: #00ABA9; RGB(0, 171, 169)
  • Cyan: #1BA1E2; RGB(27, 161, 226)
  • Cobalt: #0050EF; RGB(0, 80, 239)
  • Indigo: #6A00FF; RGB(106, 0, 255)
  • Violet: #AA00FF; RGB(170, 0, 255)
  • Pink: #F472D0; RGB(244, 114, 208)
  • Magenta: #D80073; RGB(216, 0, 115)
  • Crimson: #A20025; RGB(162, 0, 37)
  • Red: #E51400; RGB(229, 20, 0)
  • Orange: #FA6800; RGB(250, 104, 0)
  • Amber: #F0A30A; RGB(240, 163, 10)
  • Yellow: #E3C800; RGB(227, 200, 0)
  • Brown: #825A2C; RGB(130, 90, 44)
  • Olive: #6D8764; RGB(109, 135, 100)
  • Steel: #647687; RGB(100, 118, 135)
  • Mauve: #76608A; RGB(118, 96, 138)
  • Taupe: #87794E; RGB(135, 121, 78)