title: MVVM-Light pass data to new ViewModel
body: <p>Just fiddling around with some WP8.1 development + MVVM-Light toolkit and am having trouble trying to figure out how to achieve something..</p>
  
  <p>Basically:</p>
  
  <ul>
  <li>I have a <code>View</code> (let's call it <code>View1</code>) which has a control (<code>LongListSelector</code> in this case) that is databound to a Collection of items (let's call them <code>DataItem</code>) (which is populated by a <code>Service</code> from a <code>ViewModel</code>) </li>
  </ul>
  
  <p>And I want it so: </p>
  
  <ul>
  <li>When the user taps on a particular item in this control, it passes the item tapped (or a property of this item) to a new <code>View</code> (called <code>View2</code>), which will either create a new <code>ViewModel</code> for <code>View2</code> or re-use an existing one (depending on the <code>Key</code> of the instances in <code>SimpleIoC</code>, determined by some property in the <code>DataItem</code> tapped).</li>
  <li>This new <code>ViewModel</code> then uses the passed property of the <code>DataItem</code> tapped in its' constructor to fetch data from a different <code>Service</code></li>
  </ul>
  
  <p>So how can I achieve this? I am thinking of Creating/Registering the new <code>ViewModel</code> on the <code>SelectionChanged</code> event of the control, passing it in the <code>Service</code> and <code>Property</code> like so:</p>
  
  <pre><code>    private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
      {
          DataItem item = e.AddedItems[0] as DataItem;
  
          SimpleIoc.Default.Register(() =&gt; new ViewModel2(new Model2Service(), item.Name));
  
          NavigationService.Navigate(new Uri("/View2.xaml", UriKind.Relative));
      }
  </code></pre>
  
  <p>Which works fine for the <strong>first</strong> <code>DataItem</code> tapped, but not when a second is tapped. 
  <strong>Note</strong>: I couldn't register <code>ViewModel2</code> in <code>ViewModelLocator</code> as I couldn't get <code>DataItem</code> properties passed to the constructor for <code>ViewModel2</code>, which is why I'm trying to Register it elsewhere. </p>
  
  <p>Not sure if this is abiding by MVVM architecture, I suppose not as <a href="https://stackoverflow.com/a/7575052/2714911">this answer</a> states that I shouldn't be handling this in my <code>View</code>.</p>
  
  <p>So to recap, I want a user to be able to tap on an item in a <code>LongListSelector</code> which will then navigate the user to a new <code>View</code> which is bound to a new (or existing) <code>ViewModel</code> according to a property of the selected item. How can I achieve this?</p>
  
  <p>Any help would be greatly appreciated.</p>