Using the community toolkit with xamarin iOS and Xamarin Android

47 Views Asked by At

I'm currently evaluating the Community Toolkit MVVM package for a native Xamarin Android and iOS package. I know the code used to work with MVVMLight, but there does not seem to be a way to bind the VM to the UI on Android and iOS.

I did consider have the Android activity inherit ObservableObject, but this doesn't seem to tbe a good way forward.

Is there a way to bind the VM to both the Android and iOS source code and for the UI to react when the PropertyChanged event is thrown on a property in the VM?

1

There are 1 best solutions below

0
Jessie Zhang -MSFT On

Is there a way to bind the VM to both the Android and iOS source code and for the UI to react when the PropertyChanged event is thrown on a property in the VM?

You don't need to bind the VM to the Android and iOS source code. You can bind the VM to the shared code for both Android and iOS platform.

From document: What is Xamarin.Forms?, we could know that:

Xamarin.Forms is for developers with the following goals:

  • Share UI layout and design across platforms.
  • Share code, test and business logic across platforms.
  • Write cross-platform apps in C# with Visual Studio.

If you want properties react once the value of properties of Model class or viewmodel class change, you can implement interface INotifyPropertyChanged for your item and invoke OnPropertyChanged for the properties.

For more information for this, you can check document: The Xamarin.Forms Command Interface.