SHARE
TWEET

Untitled

a guest Mar 23rd, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public partial MyUserControl()
  2. {
  3.     InitializeComponent();
  4.     Model.Initialize(DI.Resolve<IMyService>());    
  5.     Loaded += () => { Model.OnLoaded(); };
  6.     Unloaded += () => { Model.OnUnloaded(); };
  7. }
  8.  
  9. public class MyViewModel  
  10. {
  11.     private bool _isLoaded = false;  
  12.     private IMyService _myService;
  13.    
  14.     public MyViewModel() {
  15.         // TODO: Add your constructor code here
  16.         // The ctor is always called, initialize view model so that it also works in designer
  17.     }
  18.  
  19.     public void InitializeIMyService myService) {
  20.         _myService = myService;
  21.         // TODO: Add your initialization code here
  22.         // This method is only called when the application is running
  23.     }
  24.  
  25.     public void OnLoaded()  {
  26.         if (!_isLoaded)  {
  27.             // TODO: Add your loaded code here
  28.             _isLoaded = true;  
  29.         }
  30.     }
  31.  
  32.     public void OnUnloaded()  {
  33.         if (_isLoaded) {
  34.             // TODO: Add your cleanup/unloaded code here
  35.             _isLoaded = false;
  36.         }
  37.     }
  38.     ...
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top