Table of Contents

ViewModelMixin

In order to add data to the prefab, you need to add properties to the target datasource class, this is done by making a mixin class, inheriting from BaseViewModelMixin<T> and marking it with ViewModelMixin attribute. This class will be mixed in to the target view model T, making fields and methods accessible in the prefab:

[ViewModelMixin]
public class OptionsVMMixin : BaseViewModelMixin<OptionsVM>
{
    private readonly ModOptionsVM _modOptions;

    [DataSourceProperty]
    public ModOptionsVM ModOptions
    {
        get
        {
            return _modOptions;
        }
    }

    public OptionsVMMixin(OptionsVM vm) : base(vm)
    {
        _modOptions = new ModOptionsVM();
    }

    [DataSourceMethod]
    public void ExecuteCloseOptions()
    {
        ModOptions.ExecuteCancelInternal(false);
        ViewModel?.ExecuteCloseOptions();
    }
}

The last thing is to call UIExtender.Register and UIExtender.Enable to apply your extensions:

      public class CustomSubModule : MBSubModuleBase
      {
          protected override void OnSubModuleLoad()
          {
              base.OnSubModuleLoad();
            
              _extender = new UIExtender("ModuleName");
              _extender.Register(typeof(CustomSubModule).Assembly);
              _extender.Enable();
          }
      }

To use the OnRefresh overload you will need to specify for UIExtenderEx the underlying method that acts as the conceptual 'Refresh' method in the ViewModel.
For example, MapInfoVM has a method Refresh.
If such method exists, specify it in the ViewModelMixin like this:

[ViewModelMixin("Refresh")] // or [ViewModelMixin(nameof(MapInfoVM.Refresh))] // if the method is public
public class MapInfoMixin : BaseViewModelMixin<MapInfoVM>

This page was last modified at 01/30/2021 12:20:13 +03:00 (UTC).

Commit Message
Author:    Vitaly Mikhailov
Commit:    941cff95afad4c6c907cea6966d56f554802b6cd
Update