Xamarin C# and Mobile Platforms - xamarin

I started Xamarin and I'm beginner. Since there is no documentation about Xamarin, when I have crash I can't find solution.
Anyway, I want to ask some question to you.
There are 2 choices: you can either use only Xamarin code with C# and this code yields to work with Android, IOS and Win Phone, or you can use separate code for Android, IOS and Win Phones. Is this information true or false? (I don't know I am exactly true.)
When I create a .xaml file with C# to yield Android, IOS and Win Phones, how can I use native pages, libraries (ex: SharedPreference). For example, I have a .xaml page and I want to navigate to an Android.Activity page - is this possible?
Thank you for your responses.

Your best friend for bugs and errors is google and stackoverflow. You can find almost everything as xamarin started to grow a lot after microsoft's acquisition.
You can either choose a unified solution like a PCL (Shared or Portable) or seperate projects.All of them are written in C# because that is what Xamarin is doing.
I don't think you have the ability to do that, but i am not sure.
You must do your research in order to find which way of coding is appropriate for your application. If you want to build something very unique with complex ui in each platform, you would probably choose separate projects. Else you can use xamarin forms to have a unique UI across all of your projects.

Related

How to print the current UI of Xamarin form crossplatform application

I want to print the current UI of a Xamarin.Forms cross-platform application. Are there any plugins or libraries available which support both android ios and uwp projects to do this? I'd really appreciate being pointed in the right direction to get started on implementing this kind of feature in my application.
I would approach this in two steps. Firstly you need to convert the current visuals into a printable file type. So assuming we are working with primarily mobile devices then we should make use of the 'screenshot' mechanisms.
There is a very good answer to another stack overflow account HERE that guides you through setting up screenshots in xamarin forms using dependancy injection. The chaps answer is straight forward and easy to follow.
Once you have that screenshot as a png or jpeg etc. It's time to print it. There are a lot of threads on xamarins developer forums dedicated to the issues around printing from xamarin, a collection of these can be found HERE.
So to start with it's worth mentioning that every platform xamarin forms (XF)supports has it's own mechanism for printing. XF does not provide any abstractions for printing in a cross-platform manner. You will need to write printing logic for each layer and expose it to XF using DependencyServices.
Android Printing - this is a link to printing in android.
iOS Printing - this is a link to printing in iOS (Heres a sample app to help you as well.)
As I previously mentioned, because xamarin hasn't created a simple cross-platform mechanism for this in Forms, it's not quite as simple as you'd think and does require some work to implement. But none of the work is overly complicated, it uses standard dependancy patterns, it's really just the bulk of code required that can seem a bit daunting.

Understanding Xamarin [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
As a complete beginner to Xamarin and new entrant to mobile app development, I have some questions about Xamarin and about the way it works which I was not able to find on the internet
How does Xamarin Cross-platform actually work? Is it any use? I was told Xamarin told Xamarin is a cross-platform mobile development solution, but when I Start off, I see it actually encourages you to create separate projects for iOS and Android. I understand that is to give us more power and there is always Xamarin Forms if we want cross-platform UI. In that case, however, I would expect the Portable Class libraries to handle all the backend logic while the native projects are used only for the UI. But when I started out, the most basic library for accessing mobile functionality (Xamarin.Mobile), is not compatible with PCL. What is the use of PCL even in that case?
How are cross-platform apps generally made in Xamarin? What is the role of the PCL and how do we get it to do cross-platform stuff?
Is there no pre-built Xamarin API which allows to do most mobile-related stuff platform independently? Seems we have to download new libraries from nuGet for every little thing we want to do which is quite painful
I hate to ask this. But is the only real advantage of Xamarin the fact that we can code in C# instead of native languages? What I was expecting is actual cross-platform shared code-base. If unity can do it, why can Xamarin not do it?
As someone who's worked with Xamarin (certified) for more than 2 years I will try to answer your questions:
1) Xamarin is a .NET framework that compiles to native code for both platforms. 2 years ago you'd create projects for every 'type' of app you built (Android, iOS, etcetera). In practise this meant you writing Activities for android (in the .NET way of doing things, but with the exact same native android types) and UIViewControllers for iOS. Xamarin.Forms has been out for a while and is a solution that will allow you to share UI Code as well as Business logic.
2) Depending on the app, one chooses either Xamarin.Forms or the native route. In case of the native route you'd create views for every platform (Android AXML and iOS Storyboarding). Additionally a PCL would be added containing all the business logic. This way you can call
var authResult = AuthService.Login(username,password);
var settings = SettingsService.GetUserLocalDbSettings();
from both iOS and Android, and the business logic for logging someone in - only has to be written once. Xamarin.Forms allows you to also share UI, by building XAML-layouts in the Xamarin.Forms project. These get transformed to the right screen type in either OS. Note: This only works properly with simple layouts (think lists, tabs etcetera). Complex layouts take way more time in forms to the point you switch to native.
3) Xamarin is only the framework allowing you to write .NET for these platforms. There's a lot of plugins available (e.g. Connectivity check) that are available. Install them in your native projects AND the PCL, and you'll be able to check whether the app has connectivity from within the PCL, or not). Xamarin is the hammer, Nuget offers the nails.
4) You can share a lot of code (PCL). My honest experience though is that most of the time you'll be building layouts (views) for both platforms. The business logic (signing in, saving items to a SQLite database) costs the least time to build. UI / design however,....requires a lot more patience. So YES you can share all business logic (as far as the used libraries respect the PCL profile).
5) Protip: Xamarin offers some free university training since they have been part of Microsoft.
I agree with the comment made by Lex Li above that you seems to be quite new not only in Xamarin space but also in C# development space, but will still try to add to the points mentioned by Eric J which I think he has missed in his answers.
Answer to Question 1:
How does Xamarin Cross-platform actually work? Is it any use?
Already answered by people before me.
What is the use of PCL even in that case?
You didn't found the use of PCL because you didn't tried to use it correct way. It's not for accessing mobile feature from common code, It's used for writing code which is common for all the platforms example for such type of code can be 'Web Service call', 'Business Logic' etc.
Answer to Question 2:
This is a very generic question whose answer is given many times, by many people. The best place to know more about Xamarin is by following the Xamarin Developer Guide
Answers to Question 3:
As mentioned by Lex Li Nuget is core of .Net package distribution and you should use it not only because of this reason but also because it makes development and deployment more easy.
Like :
1) You need not to worry about where to store DLLs (GAC/Local)
2) No need to store a particular version of DLL in fear of loosing it, all the versions are stored on Nuget Servers and Visual Studio automatically downloads the one which is mentioned in you Package config.
3) You can choose to use pre-release version of any DLL in one project and Stable version in other with out worrying about any clash.
Answers to Question 4:
I think all the advantages are already mentioned in above answers, I would request you to first try working with Xamarin sincerely and then start ranting about it.
Unless you learn Xamarin as part of the larger C# ecosystem, the questions and answers will be hard for you to digest.
1 and 2: Kind of the worst questions. So many use Xamarin. PCL is dying if you really know how C# and .NET ecosystem go. .NET Standard and Standard Library will be the future, and have already been supported by the latest beta builds from Xamarin.
3: NuGet is the core of .NET package distribution (like npm for JavaScript) and every C# programmers should use it. If you cannot get used to that, well, nobody forces you to start your own tool chain.
4: Then why not use Unity? What are you waiting for then? Xamarin has its own target user groups, and those guys do appreciate that only the meaningful code should be shared. People do love platform dependent UI, as that can blend perfectly into native platforms.

Xamarin Sample Apps for iPad and iPhone?

I wonder why none of the Xamarin Prebuilt Apps at https://www.xamarin.com/prebuilt support both iPad and iPhone? They all have the same design on each resolution. Especially Apps like 'Acquaint' would be perfect on iPad to have the contact list on the left and the details on the right. But instead it just has the same design like the iPhone Version.....
Are there any reasons why Xamarin does not offer samples with different designs depending on the client resolution? Are there somewhere else some examples?
Many thanks!
You might want to take a look at our Creating Mobile Apps with Xamarin.Forms Book First Edition by Charles Petzold.
I work on the same team as Charles and I know it's a topic he's covered in detail. The full book should be available soon too.
BTW, we are looking into creating some detailed, annotated cross-platform app samples that do all the goodies that a typical modern app would be expected to have.
I do not know of any of the stock Xamarin examples that use OnIdiom, but it just a matter of time to code them...hahahah, always just a matter of time and code. (I'm sure the Xamarin guys can chime in on this one):
Xamarin.Forms.OnIdiom Class
<OnIdiom.Phone>Vertical</OnIdiom.Phone>
<OnIdiom.Tablet>Horizontal</OnIdiom.Tablet>
In terms of finding examples that use the Xamarin.Forms XAML OnIdiom I would search Github for OnIdiom, there a few OSS examples of phone/tablet switching floating around there as I used at least one as a template to do a quick phone/tablet prototype for a client.

Best way to approach WP7 app development?

I have some knowledge of basic PHP developing however right now I am thinking about developing a phone app. I do however have a bit of a conundrum in that I love WP7 and I have so many ideas for features which can't be done on iOS and Android, however at the same time I am completely aware that my target users (filmmakers) generally have iOS or android phones.
Is there a way I can develop the app, which I will get a developer to do rather than myself, with WP7 as the lead platform and then make a relatively simple conversion to the other platforms or do apps generally have to be completely reworked for each platform?
Also, just to though it out there, any idea of where to go to find a freelance app developer?
Thanks
James
I think you have a few options, but the first question I would have is: where comes the data from. Are you the owner of the data, and do you already have a datasource from where you can get the data from? If not I would suggest take some time to write a decent 'backend' from which the different platforms easily can get the data from.
Also all different platforms have their own pro/cons which you cannot share that easily. If you build a WP7 app in silverlight/xna, you cannot directly port it to a ios/android variant, also functionality will probably look/react different. You will need different solutions foreach platform with this approach.
Another option would be to use an platform like phonegap which can create a solution that will work on multiple platforms. (It uses HTML5 to get it work on the different platforms)
Build your app on iOS and android first, and when you have an app to base WP7 development then contact a developer that has made similar apps to yours.

Windows Phone 7 : developing UI without xml

We are developing an Windows Phone 7 mobile application. We are new to this platform. In our application, screen will be dynamically generated. So we would like to render the UI
programmatically - without using any xmls. Please share some example code or resource or links, wherein UI is rendered programatically. In case of iPhone development, we referred "UICatalog" example. We are looking for similar type of example
It is possible to render the UI in code, though the examples of doing so are few and far between because it's a rare thing to do with XAML-based technologies like Silverlight and WPF. Instead, you tend to find that developers use to databinding and data templates to present generated content.
If you are porting an application from iPhone to Windows Phone (or even if you're just starting from scratch), the best thing to do is to firstly make sure that you understand the development platform. There are some great resources for this on MSDN here: http://msdn.microsoft.com/en-us/wp7trainingcourse_wp7gettingstarted_unit.aspx
The next thing to do is to make sure that you understand the Metro design language that Windows Phone is built upon. Here are some great resources in that respect:
Metro Design Language for Windows Phone 7
Microsoft design .toolbox
From Transportation to Pixels
Once you've reached this point, you will most likely realise that your current approach isn't the right one and switch to a databinding and data templates approach :)
If you are doing an iPhone port, it's important to realise that the design approach is different for Windows Phone applications. Content is King, so work out what that is, put it "front and centre", and trim away every thing else.
I hope this helps.
You may want to investigate the XNA path for Windows Phone development.
Developing with SilverLight but choosing not to use the most useful features of the platform is probably not going to be fun.

Resources