In this article we are going to see what are Contracts in Windows Store Application development. In our previous article in this series we have seen how to use Files and Folders effectively to handle the data locally and globally with your Windows Store application development. So what are contracts? is the first question that comes to your mind while reading the topic. Contracts in Windows Store is basically an agreement between one or more applications which wants to interact between each other. Contracts will be used to define the requirements that the application must react to the user inputs. Let us see the steps on how to use the contracts in our application development. [more]
With Windows Store application development we have 5 different contracts that are readily available to use it across in different requirements. The contracts that are available right now are
- Search
- Settings
- Share
- Play to
- File Picker
Search Contract:
This contract is used with in your application or with the system to search for something that the user inputs. In real time users will have the option to use the Search Charm to open the search pane and enter the search queries and select the respective app to show their search results. Let us see how we can use the Search contract setup with the code step by step. Open Visual Studio 2012 IDE in administrator mode and create a new Windows Store application in javascript with a valid project name as shown in the screen below.
Once the project is created we can see some of the default files and folders added. The easiest way to start the Search contract is to add a new item from the list of templates that are available with the Visual Studio IDE. So to add the Search Contract template right click on the project name in the solution explorer and select Add New Item. From the list of available templates select the Search Contract and click on as shown in the screen below.
Clicking ok Add will add some of the missing files that are basically required to run the application which uses the Search contract effectively. We can see a list of below files added to the project which are basically required to run the application that uses search contract. Actually Visual Studio makes life easy for the developer with the basic files that are required and common to use across the project. Now add the JavaScript file to the default.html page which is declared as a script as shown in the figure below.
Since we created a BlankApp template we need to add navigation support to the application in order to get the search working properly. Else if we use the other template that is available with the visual studio like the Grid, Split and Navigation template then it has a inbuilt custom control added called PageControlNavigator.
Basically with visual studio we have added a basic search page, but to completely utilize the search functionality we need to write our code to enhance it further which makes the search functionality more powerful. Like we need to add filters to the page, search for app data, search with empty queries, suggestions for the search made, customizing the look of the search result, navigation from the search page with the detailed page of the search etc.
Search Contract in action:
Settings Contract:
With this contract we can provide quick links, access permissions, application settings which affects the user experience based on the selection the application does. The settings charm provides a single access page where we can access all the settings that are related to the application and specific to the application. When we say contract charm its basically a simple fly-out from the right side as a menu which has all the setting details. The charm normally appears when the user taps the settings charm button or swipe on the right end corner.
Setting contract in action:
Share Contract:
This contract is used to share the content from the application to other application or service easily in a single click of the charm. Basically its likes share thorough the content from the application and get content to the application. The advantage with this contract is everything is preconfigured and we no need to write a code to activate and use it, just with some configuration we can use it as everything is maintained in the SDK. The Share contract can be supported in an application in two ways, as one is like a source which has the data and can share the data with the other application and the other is the target app which gets the data from the source and use it across to share the content. We can decide on the data format that the app should support so that the application which is source has full control over the data content shared. We need to use Windows.ApplicatonModel.DataTransfer namespace to package the data and use it across to share the content.
Play To Contract:
This contract is specifically used to play digital media content directly from the application by connecting to the server. This Play to contract is not directly available in the charm window where as we need to integrate with the application to stream audio, video or images to the client application. PlayToManager class should be reference and use it to associate the event handler with the request and pass the media element from the application to the method.
File Picker Contract:
This contract is used by the File Pickers to provide the application with files and access to the folder where the app can save the formated or edited files using the File Open Picker and File Save Picker contracts. With this contract the application gets full access to the files and folders locally and can be used by the users to browse through the folders and select the appropriate files. StorageFolder and StorageFile class objects are used to get access to the complete folders, you can get some clear idea of accessing files and folders in my previous article of this series.
Conclusion:
I hope this articles provides with some information on the different contracts that are available in the development of Windows Store application and we also seen what are the benefits of using these contracts in your application development.
No Comments
Fantastic goods from you, man. I have understand your stuff previous to and you're just extremely excellent. I actually like what you have acquired here, certainly like what you are saying and the way in which you say it. You make it enjoyable and you still care for to keep it wise. I can not wait to read far more from you. This is really a great website.
Hi! Someone in my Facebook group shared this website with us so I came to look it over. I'm definitely enjoying the information. I'm book-marking and will be tweeting this to my followers! Terrific blog and outstanding style and design.|