Skip to content

Tips & Tricks & Bits (Xamarin)

Tips & Tricks & Bits is a periodic series that will showcase things that I have found useful to know in my coding endeavors.

Here’s a quick list of a couple of things I have found useful to know when writing apps for Xamarin (check back, this list will grow):

  • Android projects hate hyphens.

    Don’t use a hyphen in an images or resource names. Using “my-icon.png” in your drawable folder will give you all sorts of strange errors, which, unfortunately, will not, in any way include “Don’t use hyphens” in the messaging at all. Use “my_icon.png: instead and all will be well.

  • Make Sure Platform Heads Get Their Packages Too.

    Even if you are only using a particular feature in your PCL(s) (e.g. settings, file system, location sensor, etc.) make sure that the platform head projects get the appropriate packages. What you have to keep in mind is that Xamarin compiles to native code and the heads need to have the appropriate platform specific libraries available so that you cool PCL code will run. Often the NuGet Package Manager will take care of that for you, but, you should always be aware for those times that it doesn’t.

  • DON’T create your UI in code unless you absolutely have to

    It is cool to create code only custom control (I do it a lot), but really, unless you absolutely have to, it is not a great idea. There is a lot going on in the simplest of controls in Xamarin once you factor in the multi-platform support and therefore, it can get tricky to manage and maintain very quickly. With all the binding, converters and commands involved in controls, it is easy to end up with strange, platform-specific issues when you start to build complex user/custom controls in code. Avoid the headaches where possible and do code only controls in Xamarin only when absolutely necessary.

  • ListView Properites HasUnevenRows and SeparatorVisibility.

    Xamarin Forms ListView can seem to make it tricky to create the UI you want in lists. This is especially when trying to get the vertical layout to dynamically “grow” the way you need it to. You also may find that (mainly on iOS) you have ugly horizontal lines dividing items. To help with these issues, Xamarin has something that UWP/WPF doesn’t have: HasUnevenRows and SeparatorVisibility. Setting these properties to False and None, respectively, will help you easily to solve these annoying UI issues.

  • AbsoluteLayout is not your friend.

    I am sure that you need this thing to be exactly here… I am sure that you think that you need AbsoluteLayout, but from my experience with Android, it is not going to be your friend. It is hard to be sure that it will look correct in all the form factors and play nicely with all the other layout settings of all the other controls. Avoid it when you can and only use it when you must.

  • Posted in Periodic Post Series, Tips & Tricks & Bits.

    Tagged with .

    2 Responses

    Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

    1. Java Development says

      Thank you for this great article, I have shared
      it on Twitter.

    2. online says

      Pretty! This has been a really wonderful post. Many thanks
      for providing this info.

    Some HTML is OK

    or, reply to this post via trackback.