Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The way I do this is to have a central controller class that the ViewModels all know about, via an interface. I then set state into this before having the phone perform the navigation for me. Each ViewModel then interrogates this central class for the state it needs.</p> <p>There are a number of benefits to this for me:</p> <ul> <li>It allows me to have non-static ViewModels.</li> <li>I can use Ninject to inject the concrete implementation of the controller class and have it scoped as a singleton.</li> <li>Most importantly, when tombstoning, I only need to grab the current ViewModel and the controller class.</li> </ul> <p>I ran into a problem with messaging where my ViewModel was the registered listener, because I was View First and not ViewModel First, I was forced to use static ViewModel references. Otherwise the ViewModel wasn't created in time to receive the message.</p> <p>I use the controller class in conjunction with messages (it is basically the recipient of all messages around the UI) so in future if I refactor, I don't need to change much, just the recipients of the messages.</p> <p>Come to think of it, the controller class is also my navigation sink - as I have some custom navigation code that skips back paging on certain pages etc.</p> <p>Here's an example of my current set up:</p> <pre><code>public interface IController { Foo SelectedFoo { get; } } public class ViewModel { private IController _controller; public ViewModel(IController controller) { _controller = controller; } private void LoadData() { // Using selected foo, we load the bars. var bars = LoadBars(_controller.SelectedFoo); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload