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!
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
So how to start, first you go to Tools -> Extensions and Updates. Then you go to Online on the right column and in
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
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
- Prism in Xamarin Forms Step by Step – XamGirl
- Check out the Prism video Guides by
it’smain supporter – Brian Lagunas
Credits for artwork components:
Mobile Icons for the banner of the post made by Freepik