Solved Exception in Passing Relative URI to Windows Runtime

While working today on a Windows Store Application I had a requirement to work with URI. Business class was as follows,

 

image

And I created instance of Product class in usual way setting values for both properties. I had put all images in ProductImages folder.

 

image

 

On running application I got following exception that given System.Uri cannot be converted.

image

 

After small research I found that WinRT does not support Relative URI. It only supports Absolute URI.

 

image

 

Now I fixed above problem by converting Relative URI to Absolute URI.

 

image

 

Exception got fixed after changing URI as absolute URI. I hope you find this quick fix useful. Thanks for reading.

Presented on Windows 8 development for JavaScript developers

image

Download resources of the session from here

My next presentation. Find details and register here

For updated from Delhi User Group events join Facebook Group here

On 9th March I presented on Windows 8 development for JavaScript developers. This event was conducted by Delhi User Group. There was decent number of participants in the event. I presented on “Windows 8 Development for JavaScript developers “. I covered following topics in my sessions

  • How development for Win8 is different?
  • Different JavaScript based project templates.
  • Work with Services and Data Source
  • Working with List View
  • Working with Templates
  • Working with Grouping
  • Working with Semantic Zoom
  • Working with Share Contract

Download resources of the session from here

My next presentation. Find details and register here

For updated from Delhi User Group events join Facebook Group here

My next session is on 23rd March. You can find details and register for that session here . See you seen in next community event.

Presenting on “Developing Windows 8 Apps using JavaScript “for Delhi User Group

Register for the Event here

clip_image002

I am presenting on Developing Windows 8 Apps using JavaScript for Delhi User Group on 9th March. Venue of the event is Microsoft India Gurgaon.

Find Details and Register for the Event here

I will adhere to my style of speaking and will present in step by step manner. I will discuss or rather code on following topics in my presentation

  • How development for Win8 is different?
  • Different JavaScript based project templates.
  • Work with Services and Data Source
  • Working with List View
  • Working with Templates
  • Working with Grouping
  • Working with Semantic Zoom
  • Working with Share Contract

We will create “Netflix Movie Explorer “in order of learning above topics.

It does not matter whether you are a beginner developer or a seasoned programmer, this session will offer you some learning.

Find Details and Register for the Event here

Quick details of event is as following

Date: Saturday, 9th March 2013

Time: 9 AM to 1PM

Venue: Microsoft, DLF Cyber Greens. 9th Floor, Tower A, DLF Cyber City, Sector 25 A, Gurgaon. Near to Sikandarpur Metro station on Yellow Line.

Find Details and Register for the Event here . I am excited to see you there.

What is Namespace in WinJS

Let us first try to understand, why we need Namespace? I will try to explain you with an example, let us suppose you have a function named GreetingMessage in JS file named Library.js

image

Now you need to use this function on default.js. When you try to call that function from other js file , you get following exception.

 

image

Essentially, you cannot access a function or variable outside its scope. Namespace in WinJS library allows you to access a function outside its scope.

  • Namespace allows you to access a function outside its scope.
  • Namespace allows you to use a function in different files along with file it is defined.
  • Namespace helps you to organize your code
  • Any type created in Namespace can be referenced outside the scope of Namespace

Now let us see that how can we define a Namespace in WinJs . You can define Namespace by calling the define function

 

image

There are two parameters need to be passed to create Namespace.

  1. Namespace name is a string
  2. Members of the Namespace as object

You can create a Namespace in Library.js as following,


(function () {

 function GreetingMessage() {

return "Hello from WinJS";

 }

WinJS.Namespace.define("MyLibrary.Function", {
 GreetingMessage: GreetingMessage
 });

})();

There are few points you need to take care here

  • Enclosed all the Namespace definition in self executed function
  • Make sure you are not forgetting the braces at the end.
  • We have defined a function named GreetingMessage
  • We have defined a namespace and function inside that can be accessed as following

image

We have defined a Namespace and now we want to access the function GreetingMessage() on the default.js file. To do this first step you need to do is to refer MyLibrary.js on default.html file. You can refer that as following,

image 
Now you can access GreetingMessage() function on default.js as following ,

var res = MyLibrary.Function.GreetingMessage();
 var output = document.getElementById("output");
 output.innerHTML = res;

In this way by using Namespace, you can access functions and objects in different files and beyond scope of the declaration. I hope you find this post useful. Thanks for reading.

Thanks to Student created Windows 8 App of my Blog

I am very pleased to write here that one student Akrita Agarwal has shown her love to my blog and voluntarily created Windows 8 Application of my blog. I am very touched by this kind effort. You can get that app from App Store from here


Link to download Application from Store


   

This is two column application. You can browse blog posts on selecting a particular blog post from left. There is feature of searching a blog post and about author as well.

   

 

This may not be the best application but we are celebrating proactive step taked by a student to create an Application for Windows Store here.

Thanks to Akrita and their friends.