It’s July already! The year is already half over, so there won’t be a better time to get out and meet fellow Xamarin developers in your area to learn about crafting beautiful, cross-platform native mobile apps in C# at one of the local conferences, workshops, or user group events happening around the world! Here […]
My newest Pluralsight course, XAML for Xamarin.Forms is now available. In this course you learn everything you need to know to achieve expertise in XAML to get the most out of Xamarin.Forms. The major topics include Getting Started Introduction to … Continue reading →
In this post I will show you how to build a range slider for Xamarin.iOS and how to write a custom renderer if you want to use it with Xamarin.Forms. If you want to use the range slider control you can write the code yourself or use the flipper forms control library, https://github.com/johankson/flipper, that can […]
I am a huge fan of Xamarin Studio and live inside of it around 50% of my development time. When I need to do library or Windows development though I head over to my good friend Visual Studio. Luckily the same exact project and solutions open in either IDE so it makes syncing with GitHub extremely easy. When I start up a Xamarin.Forms project I usually do it from Visual Studio so it spins up an iOS, Android, and Windows Phone Project. However, there are times that I am in XS, which doesn’t create the Windows Phone project so I need to add it after. Rob Gibbens wrote a great guide on adding Windows Phone projects to Xamarin.Forms in this case, but it is for the older Xamarin.Forms model pre 1.3. It is still a great guide and my guide follows this closely but updated with the new Application class requirements. Additionally, since Rob’s post we did release support for Windows Phone/Store RT apps and that process was documented as well, however Silverlight was left out, so let’s do it!
This is probably the easiest part of the process as all you need to do is right click on your Solution node and select Add -> New Project… From there you will need to find the Blank App (Windows Phone Silverlight) option under Installed -> Visual C# -> Store Apps -> Windows Phone Apps -> Blank App (Windows Phone Silverlight).
I personally name it: ProjectName.WinPhone and I turn OFF App Insights. You will then be prompted to select which version of Windows Phone to use. Simply select Windows Phone 8.0.
Restore NuGet Packages
You can always manually search for Xamarin.Forms in the NuGet Package manager, however it is easiest to actually right click on the SOLUTION node and select Manage NuGet Packages for Solution… This will allow you to see ALL NuGet packages installed in your projects and add them into your Windows Phone project. Simply Find Xamarin.Forms in the list, select Manage, and check ProjectName.WinPhone.
You may have additional NuGets installed so be sure to add those to your Windows Phone Project as well.
Fix Toolkit.Content
Xamarin.Forms uses the all powerful WPToolkit for some of its controls. When we added the Xamarin.Forms NuGet it also installed the WPToolkit NuGet and some new images were added under Toolkit.Content. We must select all of the files in this folder and mark the Build Action as Content and the Copy to Output directory to Copy always.
Add Portable Class Library or Shared Project Reference
Of course now we need to add in our shared code. Simply right click on the Windows Phone project’s references and find your “ProjectName” portable class library or Shared Project.
Modify MainPage.xaml
Xamarin.Forms 1.3 changed the normal flow of Xamarin.Forms applications include the Windows Phone’s main page, which is now inherits from FormsApplicationPage. We will now add in a custom xmlns of forms and then inherit from FormsApplicationPage:
Ensure you change “ProjectName” with your actual project name.
Modify MainPage.xaml.cs
Of course there is a bit of code behind to modify in the MainPage.xaml.cs to reference this new FormsApplicationPage and also call the LoadApplication of Xamarin.Forms. Simply replace the entire class with the following:
Ensure you change “ProjectName” with your actual project name.
You should be all set at this point with your Windows Phone project ready to go!
There are a plethora of amazing APIs built right into the core operating system to take advantage of when developing for Android, and Google Play services (GPS) allows for the addition of even more unique experiences. What is Google Play services? GPS is a continuously updated library from Google that enables adding new features to […]
I got a question from a reader last night who was looking at some code from one of my Xamarin seminars. Ryan asked about how to extract the content from a pdf file, draw on it, and email it in iOS. One way to do this is using Core Graphics, as shown in the following…Read more Reader Q&A – PDFs in iOS