ViewModelActivator is a helper class that you instantiate in your ViewModel classes in order to help with Activation. Views will internally call this class when the corresponding View comes on screen. This means you can set up resources such as subscriptions to global objects that should be cleaned up on exit. Once you instantiate this class, use the WhenActivated method to register what to do when activated. View Activation is **not** the same as being loaded / unloaded; Views are Activated when they *enter* the Visual Tree, and are Deactivated when they *leave* the Visual Tree. This is a critical difference when it comes to views that are recycled, such as UITableViews or Virtualizing ScrollViews. Create this class solely in the **Base Class** of any classes that inherit from this class (i.e. if you create a FooViewModel that supports activation, the instance should be protected and a child BarViewModel should use the existing ViewModelActivator). NOTE: You **must** set up Activation in the corresponding View when using ViewModel Activation.
        public RepairViewModel() {
            DisplayName = "Diagnose and Repair Synq Repository";
            Activator = new ViewModelActivator();
            ReactiveCommand.CreateAsyncTask(
                x => DomainEvilGlobal.SelectedGame.ActiveGame.Controller.BundleManager.Repo.Repair())
                .SetNewCommand(this, x => x.ProcessCommand)
                .Subscribe();

            ReactiveCommand.Create(ProcessCommand.IsExecuting.Select(x => !x))
                .SetNewCommand(this, x => x.OkCommand)
                .Subscribe(x => TryClose());

            //this.WhenActivated(d => ProcessCommand.Execute(null));
        }
        public PreferencesViewModel() {
            Activator = new ViewModelActivator();
            _userSettings = Locator.Current.GetService<UserSettings>();
            _apiKey = _userSettings.ApiKey;
            _refreshInterval = _userSettings.RefreshInterval;

            this.WhenActivated(d => {
                d(Close = ReactiveCommand.Create());
                d(Closing = ReactiveCommand.Create());
                d(Save = ReactiveCommand.Create());

                d(Closing.Subscribe(_ => {
                    var vm = Locator.Current.GetService<MainViewModel>();
                    vm.PreferencesOpened = false;
                }));

                d(Save.Subscribe(_ => {
                    _userSettings.ApiKey = ApiKey;
                    _userSettings.RefreshInterval = RefreshInterval;
                    _userSettings.Save();
                    Close.Execute(null);
                }));
            });
        }
Example #3
0
        public MainViewModel()
        {
            var whenAnyColorChanges = this.WhenAny(x => x.Red, x => x.Green, x => x.Blue,
                (r, g, b) => IntegersToColor(r.Value, g.Value, b.Value));

            Activator = new ViewModelActivator();

            this.WhenActivated(d =>
            {
                //create color property
                d(whenAnyColorChanges
                    .Where(c => c != null)
                    .Select(c => new SolidColorBrush(c.Value))
                    .ToProperty(this, x => x.FinalColor, out this.color));

                // create the command
                d(this.SearchCommand = ReactiveCommand.CreateAsyncObservable(
                    whenAnyColorChanges.Select(x => x != null),
                    c => this.GetImages(c as SolidColorBrush).Select(e => e)));

                // subscribe to the result of the command
                d(this.SearchCommand.Select(ie => new ReactiveList<string>(ie)).ToProperty(this, x => x.Images, out this.images));
            });
        }
 protected RxViewModelBase() {
     Activator = new ViewModelActivator();
 }
 public ReactiveViewModel()
 {
     Activator = new ViewModelActivator();
 }
Example #6
0
 protected ViewModel() {
     Activator = new ViewModelActivator();
 }