Sharing is Caring – Xamarin Forms and Prism Template Pack

Hey Guys!

Recently I got to help out a member of our Xamarin Forms Developer Community on Facebook called Elsa Bodhi she’s a great Software Developer from the Netherlands, that’s learning Xamarin from scratch and I got to introduce her to some new concepts she could use to improve her Xamarin app’s one of which was Prism, she absolutely loved it and was eager to implement it.

Once she got it up and running she contacted me again and was happy that she found out about a new cool thing called Prism Template Packs that are available for Visual Studio, and helped her increase her productivity while coding. She was so happy about her improvement that she wanted to give back to the community and help out others just as I helped her the first time she contacted me. So she wrote a post about Prism Template Pack’s for everyone to learn about them but doesn’t have the time to set up a blog right now so asked me if I could review and post it on her behalf for the community and maybe in the future she can create her own blog and keep on giving back to the community.

I got really excited after hearing her story and reading her post, so I said yes right away! haha there is nothing that makes me happier than seeing new faces in the community willing to share any new knowledge they learn and find interesting to share with others after all that’s what our community is about just a group of friends learning and improving together!

So what better occasion than my post for the Xamarin Month Initiative to let her shine away!

PD: I only reviewed grammar, wrote the back story and helped out with the banner for the post all of the content after this paragraph is completely Elsa’s first Xamarin Post!🥳, I hope you enjoy her work as much as I did!

Let’s Get Started

For those who know how Prism work, we know it’s a great framework which can save a ton of time implementing a good architecture and handy features for our Xamarin Forms App’s. For those who don’t know how it works, I suggest you take a look at the great guides XamGirl has on it: Start with Prism in Xamarin Forms Step by Step (Part 1). The advantage of Prism Template Pack, which is an extension you download and install is that if you use the Template Pack and add a page, it also adds a ViewModel for you instantly and does the registration of it for you in app.xaml.cs file.

So how to start, first you go to Tools -> Extensions and Updates. Then you go to Online on the right column and in searchbox you put Prism Template Pack and you install the package. There are a few things which are different in creating your Xamarin application.

Creating the Prism Project

File -> New -> project and instead of the old way, you go to the tab Prism. Click the arrow and Choose Xamarin.Forms. On the right choose Prism Blank App give a Name and a Location for your project, like you are used to.

You first select the platforms you wanna make your project and which Container. Click Create Project.

Voila, here we have a new project which already has a couple of really nice things. I am not gonna explain how Prism works, but what i will tell is what the project already has for us. In your platform-specific projects, you won’t have to add anything anymore, unlike when you add prism yourself the old way through Nuget. As you go to App.xaml.cs you will see that there are already RegisterTypes for your NavigationPage and your MainPage. The StartPage is set to your MainPage, as it also is in a normal project.




If you examine the project further, you will notice that there is already a folder for your ViewModels and Views present. In the ViewModels folder there is already a ViewModelBase present and a MainPageViewModel. If you take a look at MainPage.xaml in your Views folder there is one thing that’s missing, which I think is a thing the developer should have added and it’s the namespace and AutowireViewModel attribute to the pages:

There is also another feature which is very interesting, but divergent to a normal Xamarin.forms project. If you want to add a new page, you go to Views -> Add -> New item. Then you click on the arrow Prism on the left pane. There you choose Xamarin.Forms and your page you want to include in the project, name the page and click Add.

And then there is magic because the Prism Template Pack also adds a ViewModelPage to your ViewModels and if you go to your app.xaml.cs it also registers your page in the RegisterTypes. Cool isn’t it??? Happy coding!🥳.

Author: Elsa Bodhi

Reviewed with ❤ by Pujolsluis

Good References to learn about Prism on Xamarin Forms

Credits for artwork components:
Mobile Icons for the banner of the post made by Freepik

Author: Pujolsluis

I'm Luis Pujols a Software Engineer originally from the Dominican Republic. I currently work at CrossGeeks as part of an awesome team, developing in Xamarin Forms, and I'm currently working towards my certification on it as well. In my free time, I'm co-organizer of the DotNetDo software community, I also enjoy experimenting with new tech's, mentoring peers and attending or organizing software community events.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.