Get current ViewModel MvvmCross

前端 未结 2 2099
北海茫月
北海茫月 2021-02-10 17:02

Strangely, I did not find a direct answer to the very simple question on the internet.

How do I determine currently active ViewModel in MvvmCross

2条回答
  •  再見小時候
    2021-02-10 17:35

    Another way if you only want to see from your ViewModel if it's active/visible is just to have a bool field and update it on ViewAppeared / ViewDisappeared:

    public class MyViewModel : MvxViewModel
    {
        private bool _isVisible;
    
        public override void ViewAppeared()
        {
            base.ViewAppeared();
    
            _isVisible = true;
        }
    
        public override void ViewDisappeared()
        {
            base.ViewDisappeared();
    
            _isVisible = false;
        }
    }
    

    Most of the times this is enough and you can use _isVisible to check that.

提交回复
热议问题