Localized Apps for Windows Phone 8.0

If you want your app to be used by millions, localize it. In countries like India, it is a must have feature. Think about having an app allowing farmers to sell their produce directly to the customers. In such scenario, many farmers don’t know English and are used to, to their native language. It doesn’t make any sense to build an app which can’t communicate and relate with them. Rather, having an app in their own language can help boost the productivity, sale and profit. Lets see how we can build such apps.

Normally, we use resource files to store strings and various resources pertaining to different locals. To help building such resources for different locals, Microsoft has provided Multilingual App Toolkit. Download and install the toolkit from here

Lets start with building a Windows Phone application, which will welcome users in their own language. For the sake of understanding, we’ll keep it simple, one page app. The design will look like the one as shown below:

image

For this, I’ve modified the code as shown below:image

To have text for both English and Hindi languages, lets first add a text for English in ‘AppResources.resx’ file under ‘Resources’ folder. After adding text, it should look like:

image

You can add as many resources as you want to have it displayed on the screen.

Now, to enable multilingual features (Hindi in our case), if you’ve installed the toolkit then from ‘Tools’ menu click on Enable Multilingual App Toolkit.

image

Now to add support for Indian language, right click your project and click on ‘Add translation languages’. This will bring following dialog. Select ‘Hindi’ and click on ‘OK’. Note: You can select as many languages as you want. So, your app can show data to any user in their own language supported by toolkit. :)

image

It will add another file named ‘AppResources.hi-IN.xlf’ in Resources folder (for each language selected above). Double click that file to open the toolkit. In this dialog, resource file for Hindi, will be already populated with content similar to AppResources file.

image

On this screen, click on ‘Translate’ > ‘Translate all’. It will automatically translate all the texts which can be translated. If anything fails, you can manually change it.

image

Now save the file and come back to Visual Studio.

Even though, we’ve added resource strings for English and Hindi, we haven’t bind it to actual text control. Modify the text control with following code:

image

This code, at runtime, binds the textblock to text in selected language’s resource file.

After this, first, try the app using default language i.e. English. When you run the app in emulator, it will look like:

1

Here, app shows text ‘Welcome friend’ in English. At this point, change the language and local to Hindi, India to test the app in Hindi language. To do this, go to Settings > Language+Region and change it to India with following setting.

1.2

Here, you may need to restart the phone. After restart, deploy the app again and you should see the following screen:

2

This is just the beginning of multilingual app. You can add as many languages as you want. And not just text, you can add any type of resource (image, icons sound, etc…) in your resource files.

By building multilingual apps, you can reach more users. This means more money and a successful app. Hope this helps.

Refer:

Cheers,

Mayur Tendulkar

Advertisements

Build Windows Phone Apps In A Jiffy

Want to build Windows Phone apps? Don’t know anything about development or just want to get started, build working POC and hand-over to professional for final touch? Or just want to try your hands on Windows Phone development? This is the ‘right time’.

Today, Microsoft announced a Windows Phone App Studio for the savvy developer filled with great ideas but not enough time.

1

You can create apps in just 4 steps.

  • Select a template
  • Add content (static or dynamic like RSS feeds, HTML, etc…)
  • Choose the style, logo, design or do full customization
  • Use it, Share it, Publish it

2

The app created using this has a high-standard code and is ready to publish on Windows Phone store. Just download the package and publish it using your publisher account on Windows Phone Store. Don’t have one? Well, you can get one in just $19 “Summer Break” limited-time Dev Center registration offer (through August 26, 2013).

I hope, this will help you to get started with Windows Phone development and build that one mobile app, you always wanted to build Smile

Resources:

Namaste
Mayur Tendulkar

Windows Phone ‘Hello World’ App Using MVVM Light

When building any application, it is always a good practice to follow tried and tested design-patterns which will help in separation of concerns, code-reuse, maintainability, testability etc.… Just like ASP.NET there is MVC, for XAML based technologies (like Silverlight, Windows Presentation Foundation, Windows Store and Windows Phone apps), there is MVVM.

In this case, MVVM stands for – Model View ViewModel. As name suggests Model is nothing but classes representing data/entities. View represent actual view (pages in this context) whereas ViewModel does the binding between View and Model.

There are many frameworks out there which helps to build Windows Phone apps using MVVM pattern like Prism from Microsoft and MVVM Light from GalaSoft. In this blog, we’ll focus about MVVM Light.

First create a Windows Phone application.

image

Select Windows Phone 8.0 as OS Version in next dialog box.

Now, click on TOOLS > Library Package Manager > Manage NuGet Packages for Solution and search for MVVM Light in Online Gallery and install the same

image

When MVVM Light toolkit is installed, it modified App.Xaml file to instantiate the ViewModelLocator. These ViewModels are added in ViewModel folder.

image

MainViewModel is responsible to communicate between view and model. However, to keep things simple, we’ll expose a ApplicationName property which we’ll bind to Page.

image

Now, to bind ViewModel to View, in MainPage.xaml, add following code in phone:ApplicationPage element:

image

Now, bind ApplicationName to the textblock which displays App Name in MainPage.xaml

image

As soon as you modify above code, the UI changes and shows the Application Name. This is the beauty of using MVVM.

image

In next few blog-posts we’ll explore more about patterns and best practices in Windows Phone applications. Stay tuned! Smile

Resources:

Namaste

Mayur Tendulkar

Virtual Tech Conference 2013

South East Asia Microsoft Most Valuable Professionals are taking an initiative and hosting a virtual tech-conference. Best of the best speakers are going to talk about latest technology offerings from Microsoft. You can learn a lot from these sessions and you’ll also get an opportunity to ask questions if you’ve any. For more information, you can visit: http://virtualtechconference.azurewebsites.net/ for more information.

Capture

Even registration links are:

Dev Track – http://aka.ms/Ozhcyh
IT Pro Track – http://aka.ms/Uu9msj

Join us with this event and enjoy the learning.

Namste

Mayur Tendulkar

Using Raygun for Logging in Windows Phone Applications

There are very good error logging and reporting tools for other platforms. But when it comes to Windows Phone, developers need to depend on their own sources. Luckily, I got to know about Raygun.io and it is one of the best logging framework. In this post, we’ll see how we can use this platform to track, manage and report errors.

Special thanks to Mindscape for providing trial versions and details about this product. This error logging platform is available to other platforms as well like ASP.NET, PHP, JS, .NET, WinRT/WP and what not.

To use this platform, you’ll need to first create a Raygun.IO account. You can opt for a trial version. Once you login, you’ll be asked to create a new app or visit: https://app.raygun.io/application/create

image

Once the application is created, you’ll be taken to the Dashboard. On this dashboard you can see various platforms and your application key. Select Windows Phone platform.

image

Now create a Windows Phone application using Visual Studio

image

Using NuGet PackageManger (Tools > Library Package Manager > Manage NuGet Packages for solution) install Raygun required assemblies in Online category.

image

Now, in your Windows Phone’s App.xaml.cs file, create object of RaygunClient, passing your Application Key. This will require you include referred assemblies. Make a note of highlighted text.

So, the App.xaml.cs will look like:

 using System;  
using System.Diagnostics;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Mindscape.Raygun4Net;
using RaygunForWPDemo.Resources;
namespace RaygunForWPDemo
{
public partial class App
{
public static PhoneApplicationFrame RootFrame { get; private set; }
private readonly RaygunClient _client = new RaygunClient("YOUR APP KEY FROM REYGUN DASHBOARD");
public App()
{
UnhandledException += Application_UnhandledException;
InitializeComponent();
InitializePhoneApplication();
if (Debugger.IsAttached)
{
Current.Host.Settings.EnableFrameRateCounter = true;
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
}
}
#region Application Events
private void Application_Launching(object sender, LaunchingEventArgs e)
{
}
private void Application_Activated(object sender, ActivatedEventArgs e)
{
}
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
}
private void Application_Closing(object sender, ClosingEventArgs e)
{
}
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (Debugger.IsAttached)
{
Debugger.Break();
}
}
#endregion
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
_client.Send(e);
}
#region Phone application initialization
// Avoid double-initialization
private bool phoneApplicationInitialized = false;
// Do not add any additional code to this method
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
RootFrame = new PhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
// Handle navigation failures
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
// Handle reset requests for clearing the backstack
RootFrame.Navigated += CheckForResetNavigation;
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}
// Do not add any additional code to this method
private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
{
// Set the root visual to allow the application to render
if (RootVisual != RootFrame)
RootVisual = RootFrame;
// Remove this handler since it is no longer needed
RootFrame.Navigated -= CompleteInitializePhoneApplication;
}
private void CheckForResetNavigation(object sender, NavigationEventArgs e)
{
// If the app has received a 'reset' navigation, then we need to check
// on the next navigation to see if the page stack should be reset
if (e.NavigationMode == NavigationMode.Reset)
RootFrame.Navigated += ClearBackStackAfterReset;
}
private void ClearBackStackAfterReset(object sender, NavigationEventArgs e)
{
// Unregister the event so it doesn't get called again
RootFrame.Navigated -= ClearBackStackAfterReset;
// Only clear the stack for 'new' (forward) and 'refresh' navigations
if (e.NavigationMode != NavigationMode.New && e.NavigationMode != NavigationMode.Refresh)
return;
// For UI consistency, clear the entire page stack
while (RootFrame.RemoveBackEntry() != null)
{
; // do nothing
}
}
#endregion
#region InitializeLanguage Code
private void InitializeLanguage()
{
try
{
// Set the font to match the display language defined by the
// ResourceLanguage resource string for each supported language.
//
// Fall back to the font of the neutral language if the Display
// language of the phone is not supported.
//
// If a compiler error is hit then ResourceLanguage is missing from
// the resource file.
RootFrame.Language = XmlLanguage.GetLanguage(AppResources.ResourceLanguage);
// Set the FlowDirection of all elements under the root frame based
// on the ResourceFlowDirection resource string for each
// supported language.
//
// If a compiler error is hit then ResourceFlowDirection is missing from
// the resource file.
FlowDirection flow = (FlowDirection)Enum.Parse(typeof(FlowDirection), AppResources.ResourceFlowDirection);
RootFrame.FlowDirection = flow;
}
catch
{
// If an exception is caught here it is most likely due to either
// ResourceLangauge not being correctly set to a supported language
// code or ResourceFlowDirection is set to a value other than LeftToRight
// or RightToLeft.
if (Debugger.IsAttached)
{
Debugger.Break();
}
throw;
}
}
#endregion
}
}

Now, we’ll add a button to MainPage and in the code behind we’ll write a method which will throw DivideByZeroException.

 private void Button_Click(object sender, RoutedEventArgs e)  
{
int num1 = 1;
int num2 = 0;
int answer = num1/num2;
MessageBox.Show(answer.ToString());
}

If we run the app and click on the button, it will throw an exception. This exception will be logged by Raygun and you can get its details on the dashboard like one shown below. You can see the status marked in Red blocks.

image

Apart from that, you’ll also receive an email with error details as shown below:

image

This platform can help you to track exceptions in your applications, which are already published on the store and used by consumers. This can allow you to fix these exceptions and release updates/patches to your app making your app more successful.

Do give Raygun.IO a try.

Namaste. Happy coding :)

Mayur Tendulkar

Building Windows Phone apps for SharePoint

Yes. I love Windows Phone and I (sometimes) hate SharePoint, I’ve my own personal reasons :)

But still, there are many enterprises who use SharePoint for various reasons like collaboration, document management and what not. Providing SharePoint access on mobile devices can result in high productivity for employees. Indeed, SharePoint does have Mobile interface exposed for every site, but look at the web-page and people will simply hate it even more.

 

(Image From TechNet)

So, why not make it beautiful by providing rich user interface? why not make it more productive by building customized SharePoint solutions and mobile application? Yes. We can.

When I tried building Windows Phone apps for SharePoint, the biggest hurdle was authentication as SharePoint gives various options like Claims/Forms/ACE, NTLM, MicrosoftOnline, etc.. And then calling REST APIs every now and then. Wictor Willen has written a nice blog about SharePoint online authentication and you can see how painful it is to make requests here and there just to do the authentication :( :)

But, recently I found out that Microsoft has released an SDK for building such apps. You can download these SDKs as: Microsoft SharePoint SDK for Windows Phone 7.1 & Microsoft SharePoint SDK for Windows Phone 8. Personally, I’ll recommend SDK for 7.1 unless you’re using any specific features from Windows Phone 8.

Once you download and install the SDK, using it is straight forward – just like using SharePoint CSOM. You need to refer following assemblies to use SharePoint APIs in your project:

  • Microsoft.SharePoint.Client.Phone.dll

  • Microsoft.SharePoint.Client.Phone.Runtime.dll

  • Microsoft.SharePoint.Client.Phone.Auth.UI

  • Microsoft.SharePoint.Phone.Application.dll

You can find these assemblies at: %ProgramFiles(x86)%\Microsoft SDKs\SharePoint\v15.0\Phone\%ver.%\

As you refer these libraries, accessing SharePoint list inside a Windows Phone is very simple:

image

In this example, it will show you a mobile authentication page (shown below) as I’m using MicrosoftOnline authentication mode. Else, you can provide login box to get credentials from users.

loginbox

After providing correct credentials, user will be authenticated and Failed/Succeeded callbacks will be sexecuted. Here you can process the results.

image

I hope this blog post will help you to build more SharePoint Mobile apps.

Namaste

Mayur Tendulkar

Global Windows Azure Boot-Camp Hosted by PUG

bootcamp

On April 27th, Microsoft and Communities hosted a Global Windows Azure BootCamp. Pune User Group also hosted this event and it was a grand success. With excellent in-depth topic coverage and pool of speakers, this event was well received. You can check the event pictures here on Facebook.

Along with my friend, Sarang Kulkarni, I presented a session on Windows Azure Mobile Services. You can find the presentation here

If you’ve missed this session, you can find more information about Windows Azure Mobile Services at http://www.windowsazure.com/en-us/develop/mobile/
Thanks a lot for making this event a big success. You can soon find more such events lined by from PUG. And hope to see you more at PUG Events.

58090_10151657913586584_824362951_n

Namaste

Mayur Tendulkar