How to use the C# program I wrote in Xamarin without rewritting in xaml?

I've developed a educational program in C#. I would like to use crossplatform for all three devices but do not understand how to use my C# program
instead of xaml to develop my app.



  • RHeatherRHeather USMember

    I've watched 7.5 hours of Xamarin extended training on He does all his programming in xaml. I've created my program in C# winform. It is not clear how I take what I've done in C# and put it in a crossplatform project to get a mobile app.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    You re-write from scratch it in a new Xamarin.Forms solution.

    WinForms is years beyond end-of-life. There are so many base concepts that are just dead.
    For starters, no grown-up developer these days makes there UI in C#.
    Next comes the big foundation concept of MVVM binding from UI back to your data (viewmodel) without tightly coupling the two.

    Any pure logic classes you have in C# can probably carry over without a lot of pain.
    But as for everything else - Not so much.

    Make a new Xamarin.Forms solution. Then start typing. Make all new UI in XAML. Bind it back to ViewModel classes using MVVM pattern.

    If you want a 30,000 foot overview - and a walk through of making a new solution with some architecture planning to help yo not trip over common first-timer mistakes feel free to hit up my site.

  • RHeatherRHeather USMember

    Why is xamarin advertised as being used to program in C# or xamarin if I can't use the program I wrote? This is very misleading.

  • NashZhouNashZhou USMember ✭✭✭
    edited November 2017

    @RHeather I wouldn't say it's misleading because Xamarin uses C#, but it's misleading to you because your expectation of Xamarin is different from what Xamarin is suppose to do.

    From my understanding, you want to port your WinForms application into a Xamarin Forms application. I don't think that's possible and the only way to get your program to be fully functional in Xamarin is if you put investment into learning Xamarin. The answer sucks, but you'll have to "rewrite" your UI.

    As @ClintStLaurent said, the only things you'll be able to convert easily are classes/methods that contain logic. Once you finish writing your UI in Xamarin you'll have a cross-platform educational program though.

    Best of luck on your app though, app development is rough!

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭
    As @NashZhou says, unfortunately you cannot just 'lift and shift' your WinForms program to Xamarin because the UI paradigm is so different on mobile.

    What you can do is reuse your business logic in Xamarin - but your success here depends on how well your business logic is already separated from your UI in your WinForms program.

    Then you have a choice of using Xamarin.Forms (with XAML for your UI layout) or Xamarin.Android and Xamarin.iOS with separate UI definitions. Forms is more appropriate if your UI is relatively simple (although people have done complex UIs with it).

    So you do probably have significant work to do in moving to Xamarin - but at least you don't have to learn a new language and hopefully can reuse your business logic code.
  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    edited November 2017

    @RHeather said:
    Why is xamarin advertised as being used to program in C# or xamarin if I can't use the program I wrote? This is very misleading.

    Xamarin is C# and XAML. Those are languages. WinForms is a paradigm for writing programs 15 years ago.

    You're basically saying...

    How can they call the 2017 Camaro a 'Camaro' if the water pump from my 15 year old Camaro isn't interchangeable.

    If you built your 15 year old program well, then your logic classes don't have a lot of tight dependency and binding to the UI. So migrating that shouldn't be aweful. If you do have a bunch of bad practices in your old program that make it hard to move over... well.... you needed to re-write it anyway.

Sign In or Register to comment.