Best tools and practices of Xamarin Forms | Balázs Koncz | Skillshare

Best tools and practices of Xamarin Forms

Balázs Koncz, A mobile developer who is mobile

Best tools and practices of Xamarin Forms

Balázs Koncz, A mobile developer who is mobile

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
19 Lessons (1h 2m)
    • 1. Introduction

    • 2. Simple data binding

    • 3. Keeping the UI updated

    • 4. Commands

    • 5. The Locator pattern

    • 6. Introduction to prism

    • 7. Parameterized navigation is prism

    • 8. Binding events to commands

    • 9. Dependency Injection

    • 10. Consuming REST API Part 1

    • 11. Consuming REST API Part 2

    • 12. Use multilanguage resources in C#

    • 13. Use multilanguage resources in XAML

    • 14. Display Toast notifications

    • 15. Find geo position

    • 16. Check the battery state

    • 17. Check network state

    • 18. Use accelerometer

    • 19. Scan fingerprint

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

nce you decided to go cross-platform with Xamarin Forms - I offer you a nice collection of tools and practices. My expapnding course shows you the tips and tricks of Xamarin development and MVVM pattern. You will learn how to apply Data binding, viewmodel locator, and commands in XAML and C#.

By the end of the course you will:

  • Master data binding in Xamarin
  • Apply ViewModel Locator
  • Bind events to commands
  • Use Prism framework  
  • Build MVVM arhitectured software with or without Prism
  • Exploit the device capabilities like GPS, read network information, battery state, scan fingerprint etc...

The followings are protected by the copy right of creative commons, that's how I credit the creators. I am really thankful as they all did a nice job.


The gentle man logo:
Vintage vector created by Freepik

*Musics in lessons:

music 1:
Art Now by Alex (c) copyright 2011 Licensed under a Creative Commons Attribution (3.0) license. Ft: Snowflake

music 2:
Hanging Eleven by Kara Square (c) copyright 2016 Licensed under a Creative Commons Attribution (3.0) license. Ft: Blue Wave Theory

music 3:
Thanks for: hooksounds.csom
Music by HookSounds

Meet Your Teacher

Teacher Profile Image

Balázs Koncz

A mobile developer who is mobile


Hello, I'm Bal?zs.

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Your creative journey starts here.

  • Unlimited access to every class
  • Supportive online creative community
  • Learn offline with Skillshare’s app

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.



1. Introduction: Howard and back onto the best tools and practices examining force. This is just the first intro video to get you started in this course. First, I want to tell you what equipment I use for development. To tell the truth, I started all the rich a laptop because it's totally enough for Android and doing those development. But if you want something better, you should get the screen. Also, that size should be at least 21 inches because you can see the quote much better, and you are going to have much more space to work. I less is a bit different. You made a mecca west to combine the court toe iPhone or iPad. You may try to be a hacking door to save money, but I'm maurico and toe by a McNamee. That's the cheapest apple available animal that you can get, and you just have to switch it on and everything works. It's more reliable than building a special PC and India, and it doesn't even works because something is wrong with the bias. I don't wish to see you what I saw. Also, the Mac Mini works with any mouth, but I recommend you to buy a Mac keyboard because its layout is different from what you got usedto in PC 2. Simple data binding: Hey there in the first section, I'm going to show you how data by the works examining its ah, big different from Windows So I recommend you to change is out. If you are already familiar with that, feel free to skip to the next lesson. At first, we are going to create a new cross platform project, select examined cross platform option from the list and give some fancy name for your solution. Like deal data binding in the pop up window said you white technology toe summer informs and the court sharing strategy Toe portable class lad, really in the class library, you should add two new for others, 1 40 pages and one for the few murders. Once Artem moved the main page to the pages border and at a new class, The View Mothers Quarter Court Main view Mother This Plus we lay out the context off. The main page is going to contain two fears. Was Title and Key vert. You must initiate them with some simple values in the constructor just for making things easier and faster. I recommend you do with the crap for code snippet in visual Studio and the Seater, but there are many other stupid that you can explore. Also outlined the givers setter. That's right. It's value to the output cancer every time it changes. Be careful you can use Departed about fried time mattered only in department. Now let's go back to the main page dot example and create the view. This you, I is goingto be very simple. It's root is agreed with street girls. Luckily, Examiner didn't change much since Civil right in the first role does the label that shows the applications title set its wound toe something impressive and align its text vertically to the center. Don't forget to create the data binding between the Labours text and the View Models. Title also sent a binding toe One way. This means that the titles value where we're at only once, when the pages created the entry is an input field. Examining forms just lightly textbooks he windows, place it in the second row and bind its text toe the giver in desert row foot mystically out with two labels. This is going to show if do you? Why gets notified when something changes in the view model. The last thing left to do is to set the context. Probably you have used the data context member you windows. The situation is pretty much the same. Just use binding context instead and set it to any stance off main view model. 3. Keeping the UI updated: to implement the I'll notify property changed interface means that your class has uneven called property changed. Why you're up runs. Do you? Why is listening? If this even was triggered or not? If it is, do I updates itself? What you need to do is to fire this event every time when a property's value changes. Also, it is useful to speech the binding mode to two way. This means that not already. If you mother can change the state off, do I but you. I can also notify the view murder about changes. That's how when the user interact with me, why the view Mother state with change or it is a good practice to create a base class that implements I not to five past changed, and you can derive motors and view mothers from that base class currently accorded observe able object. The point is not right. The new check and even trigger in every glass as it will violet. They don't repeat yourself principle. Using today's property changed method, you need toe pass the updated properties name all the time. That is why you need to use the cooler member name. Attribute. This is a reflexive factor that you can use to get any members name that would call race proper to change faction 4. Commands: I think I'm going to show you how to display a collection off items and attach comment to battles for say, if I were at to know Rose to do Y and press the butter and the list view in degreed. As you might expect, pressing the butter were at new items to the list. Basically, things are pretty much the same that you got usedto in civil right or windows runtime just set up first the comment and item source with biding in the view. Mother, you should create a property called at common, and it's type should be. I command the command class is an implementation. I command examining forms. It expects the delegate. What is a reference to a mattered Toby ran when this button was pressed. Let's call it execute and comment for the Devil Collection. You should use the type off apps available collection. That's how you can keep. Do you? I updated without firing. The property changed event manually. Now. In the end, let me just and a couple of examples values 40 demo collection 5. The Locator pattern: I think I will show you how to handle multiple view mothers and never get between pages. Let's expend the demo application with two pages with carpets and person page. I am goingto add to batons to the bottom off main page that were handled. The navigation it takes just agreed with two columns to arrange them. Now let's end the five. I am going to create 35 for every page, the murder of you, Mother and Review. So in the end you have to create six new guys. The carpet and person pitch in the Pages folder, the car view mother and the person. Few murder in the View Mothers folder and the car and person classes in the motors border. The person class were contain name, age and the job members, and the car will have properties like type, model and year. The view Miller's are very simple to now. I just want to dissipate datas and no magic. Better that you need to use its particular property with the type off model and set its values in the constructor. Let me just your typical examples, like Tesla will do ls for the car and for the person is going tobe a job from engineering. Now I will create a new border world locator and place the class inside it with the same name. This is going tobe a the view model locator Basically what it does, it records the few mothers off your application. Well, you need a new page. You should always add its view Murder as a read only property to the locator. This locator actually has three read only properties for the main few border carve. You, mother and person view mother in the carpet I will use agreed to arrange d labels. It is going to contain two columns and three rows, as you may expect in the first role you were seeing. The type is Tesla with data binding, of course. Then in the second draw, the mother is s bombs, two car dot mother property and in the last one is the year to make the data binding work, you are going to need an instance off the humidor locator. The tricky part is that you have to access this instance in the dog's hammer. That's why first, I will declare a new ratios dictionary in the content Page three sources. Also that smile on the locator name space, and when you have it, you can create an instance off locator with some key Inside the Researchers dictionary. I were set up the binding context inside the Greed Center, piling Shores to the locator that you just created and the past to the property that holds the view Mother for the current page, I were Anybody navigation between pages by creating even handlers for the clicked Kieran's off these two batters. Here, you have to call navigation due to push a thing and pass one object off the requested page . Also, it is necessary to modify the app dot exam er dot CS and este. She ate domain page as a navigation beach. 6. Introduction to prism: making things for much easier. You should use the prison template instead. Off the beard in cross past Form one. Check out the extensions and updates in visual studio and search for prison template back Donald and install this extension. If you do not have it already where you are down, start a new project, look at the tempted groups and select summary informs under prison and then pick the prison Unity are suffering for from the list. This tempted creates even more cold that actually anybody really needs you can clean up the body off. All navigated to function in May Page view model, the Labour from Main page and the navigation parameters from the APP That exam er, don't CS. At first I am going to show you how navigation works, but this means that I need to do a sink to before I really anybody user to medicate to a page that contains some details. That's why Dumaine, if you wonder, needs a property called show. Details comment. Note that the properties type is still I command. But now I used the delegate comment implementation from the prison library. In the view it is enough to place the baton and bind its text and comment to the complying properties off the few murder. The financing is that you will never have to write the view of the locator by hand again as the prison fearing work automatically viers the view orderto a page, relying on exclaim, Now let's build a couple of things For the application, I will add a new property called Details Labor Toe Hold from text 40 button. Also, I will end a prison countin page that is located in examining form Stamford's off Prison Group. When you create a new prison content pitch, the framework will automatically at a properly named view under fire to the View mothers border. This pitch is going tobe a simple just like I do on I've wrote before. It will display the properties off a person. It will tell us someone's name Starship and the bounty on his or her head. You can now apply data binding without manually setting the binding contract. In this case, I am going to omit the motor and store every property in the view Mother, as I mentioned. The are the name Race starship and volunteer. If you check out the details you mother page definition. You should not think that it inherit from the bind able base. This class is a part off prison framework, and it already has an implementation off property changed toe trigger. This event you should call the set property function in the sector. Fears off a property to perform navigation. You are going to need an instance off my navigation service, but a new parameter to the view mothers constructor. So it's going to expect the navigation service later. Just call the navigation service, don't navigate a sink function and passed the name off a page as a string where you want to never get and one last checkpoint. Go to the capital Examiner that CS fire and look at the register type message. Now you can see that when you created the details page, the prison framework has automatically added this page to the container so you can be sure there are going to be no problems when you are navigating to this page. 7. Parameterized navigation is prism: that you have just beer. You will notice that it practically works, but it lacks data to be displayed. Let's make the situation a bit better. Any time where you want to pass data from one page to another, you should use navigation parameters. Class this object well behaved like a dictionary that has string keys and values off object using the IT function you can load it with. Where you that simple is that in the end, just past the parameters object to navigate a think mattered every page that sense or receives data by navigation must implement the navigation of air interface toe handled the received data. You just have to read the parameters value by i d in the own navigating to or all navigated toe. 8. Binding events to commands: For example, I have to pretty much rearrange things on the main b g y. It's going to contain only one list you with a couple off people, and if you sect any off them, the APP will show the details off that person. To achieve these first, you have to mount the behaviors name fifth from prison and add a new even to come and behavior in the least use behavior as you want to wrap it. Comment. When a user types an item in the least, you have to set the even name, toe item step and the government toe item tapped command. Actually, this comment is goingto be implemented. Interview Mother. And don't forget to set the even our experimenter path toe item. That's how the View Mother will be able to find out which item Waas clicked in the view Mother you have to define. Of course, the item kept command, but its implementation will be a bit different. You need to create an instance off delegate command, but used the generate parameter with the type off objects. This means that the execute item tapped mattered will receive an object barometer well done , Just clean up the court from unnecessary comments and properties. Well, I want to get rid off the object. Evert. So the time has come for a factoring the properties off this person to a separate class. This factoring waas pretty much necessary. Anyway, I am going to make things faster with creating this new class, making it inherited from behind able bays and just replacing the fields and property there from the details page you mother also let's add a constructor because it looks fancy Next step as I want to display the collection off people somehow. So I need to declare and observe Able collection off person and I'm going to name it people . If you remember, this was the properties name that I bound. The least views item source to this collection will be created and loaded with values into constructor. I am going toe Add Hansel, Job Hot and Greedo with some example data then did it. Everything from executed show details, comment, even the message itself in the execute item kept command. I will recreate the navigation with barometers, but it will be modified to best only one parameter. And this is the object off the selective person cystic were. So what simplifies things on the tts page view? What are also you just have toe and a person property and right that the parameter that you received from main page you mother, the final touch is to set things in. Do I In the main pitch, it will be nice to create an item template for the least view. Actually, this is nothing more than Labour. What's text is bound to the person's name and this is inside of Utor declared. It's a data Tempus In the details page, you have tow update the data binding because the properties, like name, race bounty, are now encapsulated in the person property and cannot be accessed directly. Interview model. 9. Dependency Injection: Theo. It is not the best practice to retrieve data in a human of contractor. It is far better to separate this Carson's and re factor did Italy to your court in a service class foresees I am going to create services further and then the people for their inside. There. I am going to taste interface called People Service and its Implementation the People Service class. The core off this service or detector is to get people are massive. This faction returns with a Nyima River off type person, and it's values are going to be the same that I took from the view of this constructor. Just now, I use the you'd return statement to put data Indeed, that I enumerable interview of this constructor. You should add a new parameter with the Type Off people service. Now you can look through the values off, get people function and on each of them to the observe Able collection. But how were prison? Find out rich class has been connected that implement i e per service. The answer is an essential attribute on the given classes. Names please. You must use eggs entering that, forms the dependency and then said the type off the service class 10. Consuming REST API Part 1: for this example reviews sw FBI dot com Here you can get pretty much type of data, but for now, it's enough to quiet the people at the beginning. I will build up the same architecture as before, so I will create an interface class and cordon I person service and person service. It's only method the got passing by I d really return the details or forgiven person as it's going to be a long running task. I have to prevent the service from locking, do you? Why, that's why this matter should return a task that round's on different set. Consequently, you have to create fire and wait but task inside the get person by idea matter. There are many ways to Donald Data from an online database. At first I am going to show you the easiest possible way for these. Open your new cat package manager and search for flair. Don't, Http. This better requires only a string that countings the address that you are about to establish connection with once you have it just used to get string casing faction that were download the data in the background and store it in a string variable I guess it is not a surprise if I tell you that it is better to work with the custom tack than a string. As a result, it's a Jesus drink. You need to use digital converters. Destiny, your life object method. Read the Jerrick parameter off person. Actually, this convert er, needs to import digital string and DJ Zone converter that I am going to write in no time. Let's add a couple of new for others and the glass quote person converter. This class won't be inherited from Jason Converter Us. You can set can convert to return true or the time. But the point is to write a nice and used for three JSM method you must loot the geezer reader is a G object and then find each of its very was according to their key, so off these values might happen to be released or are a But now what you need in a single value. So UK was the first or default method when done. Return with a person object with these values. OK, now let me just put things in order. In person service, I will mild the name space off person converter and I really am. The String two responds instead, off relaxed this service character with a single item at the time. Therefore, I really was before loop to create ideas, execute inquiry and, at the result, to observe able collection. Also, you should know he was the person service instead off people service. Now that there are a couple of things left to do, I really register the person service and it's near space for dependency, injection and rewrite the service address because it was wrong. But now it's fixed. Also, check out the android manifest and look for the Internet usage permission changing books to anybody up to use the Internet. 11. Consuming REST API Part 2: thieving lecture. I used a single string and the message to create an FBI core. But there is a better way. What's more flexible? But for this, be sure that you have the Microsoft dot net dot H DTB assembly installed. Use your noodle package. Manager toe, Check it out. I am going to use an issue TB client toe handle lab requests and then separate the base address off the FBI from the specific service location. On the other hand, it is useful to set the default time out that the http client is willing to wait before it declares the request. Toby failed. Currently, you can refer to the service location with the string off people bad and the idea off the person that you want to see. The information and the base address is Theo. Http. Sw FBI dot Seal their FBI there Before communicating with the FBI, you need to create an http request message where you set the http message and the service location as I only want to breed data from the server. The method type will be get when you are done. You think Leon's Sanjay Singh function and wait for the response in this database, it can happen that there is more person with the given I D. That's why it is recommended to Jack Therese plans message. And if it shows that request was not successful, you must handle it somehow. But in case off success, just read response content as a string and continue everything the way before. 12. Use multilanguage resources in C#: I think this really interesting and useful topic on this is language supper. Now I am going to create a simple examining forced application with portable cost library. Of course. Uh, let's begin. I will create all your labor and on import feared into you. Why? And of course, if you said the text, fear and the place wonder here if we work. But this is called heart. According this is what needs to be changed. The key to support multiple languages is to use for free shorts fires. The default war must be named at pre sources and all the others should counting the 1st 2 letters from that given language for Exanta, the German resources will be named every shorty's dot de. You must define the search title and the search placeholder in both five And there you should write the text that will appear in that give a language. Now you are ready to use the dictionary in the sea shackled. Just get the up the shortest class and you can see every record off your resource as a property give you the try and run your cold. Just do it. Example Declarations from the view 13. Use multilanguage resources in XAML: you are about to. You trusted resource fires. In example, court things get complicated because you need to rely on the current devices language settings. Therefore, you have to set the application of Catcher Court England. To solve this problem, you need to use the trick off dependent injection, so you have to create an interface in the class library that defines matters for reading and setting the capturing. Four. You don't need to care about the implementation yet. Just go to the AP exam for the CF and check if the running operation system is android or I Wes, if so, used to dependency service to get an instance off. I localizer, then ready language settings from the device using to get capturing for method and set the got train for in the up three sources and the localizer when you are about to use trusted resource fires, in example, could things get complicated because you need to rely on the current devices language settings? Therefore, you have to set the application of capture Court England. To solve this problem, you need to use the trick off dependent injection, so you have to create an interface in the class library that defines matters for reading and setting the capturing. Four. You don't need to care about the implementation yet. Just go to the AP exam for the CF and check if the running operation system is Android or I Wes. If so, used to dependency service to get an instance off. I localizer, then ready language settings from the device using to get capturing for method and set the got train for in the up three sources and the localizer. Wait, it's time Wait clean up. Work way He's drinking. Although the location service is ready, there are still things to be done to support translated text In Examine Cold, you must write an extension class that implements I mark up extension. This class will use resource manager that is created according to the location off the earlier or did Fisher spies. This location is toward into the short idea field, and this fee short major, as I told before this determines which language must be used. Currently, it's text property. We'll have to value that you type in the Examiner could, after the EU's off this translator, so that should be the key off a row in a resource is and then the resource manager were used this key to determine which text must be displayed 14. Display Toast notifications: in this section, I will discuss a couple of interesting topics about how to use sensors and other capabilities off the operation system. For this demo, I'm creating a new product and change it class library to use for the $5.1 version off donor framer instead or for about five. This is really important because the packages that I'm going to use may stop supporting for not five in the future or they already stopped doing it. Okay, in the main view, I really fight agreed to arrange items because I want to place a labour in the upper part off the page. The shoulder is that when you press any of the buttons below. Also, I relate to use a new class and quite Mordor that influence the I Not if I prophetic changed and it's going to have only one property called there is that this is needed in orderto enable data binding in this application and to store the result. When you read it off from a center, the implementation of property changed, if just regular one. There is no magic or friendlier style in the main page. Hold behind, I will create a fared 40 mortar to set up the data binding. Also later, I were need to use this instance toe right, censored data into it as the 1st 1 that I assure you is soft modifications. I create a button and said its text toe show notification and create. It's even teller or so, In order to provide this functionality in cross platform environment, you have toe hold a new package from you. Get package manager. Its name is toast. Don't force the program. You have to install the latest version for all the project in the solution before you could do anything with notifications. First you have to get an instance off. I toast notification. Er later, I will show you how to reduce their one or so. The notification options contain basically everything about a notification that is, Toby this plate here I said its title description and any boat clicking well you are now is design just called the notification er dot notify factor Here, you need a delegate. That is a reference on the method Toby run. When the notification waas handled and I mentioned you need to register a tow pontificator class in each platform for these just utility deep and then service don't register method. And those notification dot in its function in case of problems like interest since stairs that's may happen. It will have toe The using is manually They are the examining that forms and blocking dot toast grow on way. Wait there way Don't clean up. Wait, - You may go. Hey, that just way. 15. Find geo position: looking really use location service. So just create a new button with text and uneven. Please no. Then go to your new get package manager and search, for example, does plugging the Geo locator I will use the street that zero dot for version because the latest one is not comfortable with my currents. Acting's one dumb get an instance off course Jew locator and said its desired accuracy toe anything you would like to. I were started to 60. Now you can get the position using the get position A sink function just said it's time out because if it cannot find the location in that time this message, we're throw an exception. In the end, I were print the longitude latitude attitude toe Any other GPS data retriever in Android You must not permission toe find location and course location. You should also take the Mork location for testing on think data in Iowa. If you must set these permissions in the in food bought playlist file what you must aren't on the N s location. Always use it'd description and N s location when in usage description 16. Check the battery state: my real filed a button off the early awards. Now I am going to check the battery toe any of the destruction. Download the 3.0 dot one version off event dot blacking dot battery package. Unfortunately, it's latest version did not really work for me, but you can give it a try. Wanna go to the battering buttons even please enough and get an instance off cross battery that current. With this single toe, you can check and display the battery state power short just as its remaining charge percentage when don right the result to the mother and see if it works. 17. Check network state: that information. I recreate the bottom as I usedto on. Look around in you get package manager. Do you want that I actually need is named exam Dark blue gin don't connectivity. Now it's okay to you. Deleted version. Anyhow, I tried. I couldn't drawing any product with it here. The solution is similar to the ones I discussed before. Get to the instance off crossman activity that current. And now you carry the networking formation. As many off these data's return a list or Aboya or it is not sure that they even have a value. I have read some strength in the motor. So let's check if the device is connected to any last work or not, then the type off connection and the used bandwidth. 18. Use accelerometer: on your device, depending on its model or luckily, there is a package that supports all of them. This is deploring the sensors, and I am going to use version. What does zero. That's zero. In this example, I will show you how to read data from the accelerometer to provide counting your service. I will create a new class called Moshe Reader, and I were implement the I observe able interface with the generate type off. More sure, reading my aim is to fire and even every time when a new marshal reading value arise. That's why I created a delegate. And even the all next message will be called every time when New Very was worried. So the body off dysfunction is just a perfect place to fire this event in the centre battles even tender. I have to create a new instance off this Moshe reader, just as the cross tens or spa accelerometer. Well, I have these objects. I subscribe and you even tender toe. The motion changed the vote. Also, I have to subscribe the motion reader to the Xterra meters when greeting taken and store. The stuff description is an object in the motion teams, even Handler. It is enough to print the new values. But I don't want to read the accelerometer forever and ever so I will re factor the reader toe on a disposable feared off main page. And then I really was in if as block to start or stop the reading, depending on the reader's value. 19. Scan fingerprint: for the final actor I have an interesting topic on this is the fingerprint scanner. I will add a new bottom as always and check out. Do you get package manager? Do you want that I need? It's plugging dot fingerprint. That's really straightforward, exulted. Using the cross fingerprint cast itself is not difficult. You have to call the authenticating function toe. Ask the user for his or her finger. It's also useful to pass the cancellation. Talker don't can interrupt the process any time the authenticating function returns a bull , depending on the authentications result, I think that fear. So the point is that you can write. And if, as block toe hander there is that for now, we're just creamed if the user bust or not.