Custom Control in Universal Windows Platform

Create a New Project in MS Blend and name it whatever you want.

Now Add a New User Control by just clicking on to the project and add new user control and name it according to your requirement.



 

Add a Rectangle where you put Image and TextBlock control by just drag and drop.

 

Now go to the back end file of this user control and add some dependency properties by just typing propdb and just press the Tab two times . Boom ! that's a new shortcut for creating a dependency property.

Now for Rectangle you must have to name the property that you want to add in custom control.In my case I just want to add a Brush property of a rectangle therefore I simply add a Brush property.After this you would have to change the name of owner class to your usercontrol name and set metadata to null .Same is the case with TextBlock and Image.The only difference is the property name and type.For TextBlock you have to set the type string and for Image you have to set the ImageSource property.


 

Now just save your project by pressing Ctrl+S and Build your Project by pressing Ctrl+Shift+B.

The tricky part starts from here.Now we select that particular control which we want to bind with the CustomControl.So simply select that control and in the properties window select particular property and create data binding.After this a pop up window will open up and simply select the Element name and User control and give a property value and Press OK.Same is the case with all the controls.









After this Build your project and go to the any Page of your application and when you open the Assets of your application you will notice that your custom control is available here.Simply drag and drop your control into your application multiple times.This thing will save your precious work.



 

Now if any time you want to use that custom control you simply drag and drop into your project.The main purpose of this Custom Control is re-usability.

Ebook Download
View all
Learn
View all