Xamarin Forms Customer Control Library - xamarin

I need to create a reusable Xamarin Forms control that will be used in two separate projects. It does require custom renderers for IOS and Android. The problem is I cannot figure our what kind of project to use to create a reusable custom control library for Xamarin forms.
Every site seems to talk about creating customer controls that can be reusing in the same project. But I need it in a separate project for reuse.
Can someone please point me in the right direction.

Depending what are your needs regarding multi-targeting, using a solution with a shared project of type MSBuild.Sdk.Extras could be very helpful. You can then packed your shared project into a package that you can reference from your apps project and use locally.
Examples that might guide you and shows you the path are known nuget packages that are being used by app developers cross-platforms, just an example Xamarin.Forms.PancakeView.
Related to MSBuild.Sdk.Extras: How to use different base class in custom control depending on platform target?

Related

Cross Platform Blank App Xamarin Project

I'm trying to create an app using Visual Studio and Xamarin that will be cross platform. I've been trying to follow a tutorial I found online to do this.
When the guy in the video went to create a new project, he had the below screen, and created a Blank App (Xamarin.Forms Portable
I've installed the necessary components (Xamarin, WPF and a couple of others) with the IDE, however I don't see this option.
I've created a project using Mobile App (Xamarin.Forms) but it doesn't have the same structure as the desired template. Am I missing a component? Is the template called something different now?
The video is almost two years old, which means that some parts look different today.
If you click on the create a new xamarin.forms app, you will come to a new step where you can choose a blank app.
Then you have a choice, either choose shared projects or .net (portable).
The .net will give you a portable class library, like that in the video.
The two methods have different advantages.
Read more in the documentation: https://learn.microsoft.com/sv-se/xamarin/cross-platform/app-fundamentals/code-sharing
I hope the information will help you!

Consuming a web service with Xamarin forms

I am learning Xamarin Forms, and I have a few questions.
What's the Portable project that appears in demos and tutorials? My project from scratch is not called Portable.
Must I make my own service interface? After I add the Web reference, References.cs has generated classes and methods. Why not just use those methods directly?
When creating the app, make sure you select Xamarin.Forms, as well as Portable Class Library.
The Portable project (aka Portable Class Library, or PCL) is where the shared code goes for your Xamarin.Forms app. For example, your UI, Models, and View Models will go into that project. You mainly need to worry about the iOS and Android projects for Custom Renderers and Dependency Services, to create custom UI or platform-specific functionality that Xamarin.Forms can't do.
As for consuming the service, its not necessary to create a service interface (I assume its a RESTful service), but it will help you in being able to use the service more easily.

Cannot add Judopay to Xamarin forms project

I am trying to include Judopay in my project, and I was able to add it to Android and iOS, but not to the Xamarin forms project. There is no NuGet to be included and I can't seem to add the component reference. Any idea on how can I add it? I cannot use any of these:
using JudoDotNetXamarin;
using JudoPayDotNet.Enums;
using JudoPayDotNet.Models;
Again, they only work on iOS or Android, but not Xam forms.
That is because they only provide platform implementations. You will need to tell your Forms app which implementation to use at what time.
The correct way to go about this is with some form of IoC, using dependency injection or service location. Luckily Xamarin Forms has this integrated:
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/dependency-service/introduction/
Using the references from the Android or iOS projects in your shared code will likely not work completely or break things. Maybe not immediately but surely later on. (Except when there really is no platform-specific functionality, then you might get away with this.)

Xamarin Forms + Parse: PCL vs Shared Asset Project

I been set the mission to look at Xamarin and its cross plaform / code resuse ability, I come from a iOS/Android background.
I want to aim for the holy grail of one universal front end (basic) and one reusable service layer.
I created my first project as a Xamarin Forms PLC, hit the issue it can not support compiler directives, which seem to be something your going to need. Also I was unable to add Parse package to the PLC. You need to reference it per platform / write code per platform?
I have now created Shared Asset Project, the default setup (new project). This does not allow me to add parse to the shared layer. Some of the examples I see add a new project called service, what type of project is this?
So, my question is, forgetting how many members are in a dev team, which one (PCL, SAP) lets me have a universal backend (parse).
I found a Github sample project that could help you. It can be found here: Sample Parse Project
The link to the xamarin component can be found here: Parse component This Xamarin Component should be able to be added into your project and it should get you started immediately. Also when you add the component to you project you should be able to view sample projects that come along with it.
I would start with the sample project and see what I can do with it, but it should become a lot easier by just adding the Parse component in. This would make it so you could probably use either type of project with some Dependency Injection.

Integrating xamarin, CouchBaseLite, MVVMCross and SyncGateway such that View changes with database

I am working on a xamarin project where i use CouchBase Lite as my Local database. I also want to use MVVMCross library. Could anyone specify where should i include couchbase-Lite library, MVVMCross - hot tuna library(like class library or portable class library or platform specif project) such that view model gets notified about the changes in Couchdatabase.
Basically i want to change the view whenver there is a change in database i want to change the view with mvvmcross. Am using syncgateway to sync with server Couchbase bucket.
I am new to Xamarin, MVVM and CouchBaselite.
I couldnt find any concrete example for all this.
Thanks in advance.
I would perhaps just use the CouchBaseLite Xamarin Component. If you are wanting to access this in your PCL Core project you will probably have to create some sort of wrapper around the component and inject it properly into each platform. You can use the MvvmCross plugins wiki to get you started.
I know this is an old thread, but there's a new MvvmCross plugin for Couchbase, and basically does everything you want. It's in alpha, as of this writing on Nuget, and open source on Github. I was actually looking for the same, and happy to have found it! :)
https://www.nuget.org/packages/MvvX.Plugins.CouchBaseLite.ForestDB
https://github.com/mathieumack/MvvX.CouchBaseLite

Resources