← back to the blog


Xamarin - Better Practice

Posted in Xamarin by dake

Better Practice

Yeah, hard to be the best, I think depend on the Enviroment or what you try to build the Practice of how to build Xamarin might end up differently.

avoid use x:Name= at the control

It's better to use Xamarin's MVVM model to bind value to the UI, so you don't have dependency of UI and backend Model. For instance, if you have x:Name on your XAML, you C# side is using that name, then if you just remove the entire XAML section and replace the new one, build failed. Your XAML is tired to the XAML.cs code.

  <Entry x:Name="MyName" Text="{Binding MyNameAtModel, Mode=TwoWay}" Placeholder="My Name is" Keyboard="Text">
                                </Entry>

Use CachingStrategy="RecycleElement" for ListView

Use RecycleElement for ListView's CachingStrategy, this is better performance.

    <ListView CachingStrategy="RecycleElement" 
                              >