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
- Play to
- File Picker
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.
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:
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:
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.
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.