title: WPF - TwoWay binding to Image
body: <p>I have a twoway bind that works on one page. I will show how the data gets there by including the declaration code (not complete).</p>
  
  <pre><code>&lt;Page.Resources&gt;
      &lt;local:myViewModel x:Key="myList" /&gt;
  &lt;/Page.Resources&gt;
  
  &lt;ListView x:Name="mylvw" 
            DataContext="{StaticResource ResourceKey=myList}"
            ItemsSource="{Binding Path=myItems}"
  
  &lt;Image DataContext ="{Binding SelectedItem, 
                        ElementName=lvw, 
                        Mode=TwoWay}"
         Source="{Binding Path=myImage}" /&gt;
  </code></pre>
  
  <p>So I click on the item in the listview and it populates the image with stored image and I am able to change the image using the TwoWay bind.</p>
  
  <p>My problem page has a different setup. I want to show the selected listview item (ViewModel) in a new window. I am calling the window from a Command in the ViewModel and setting the Datacontext for the Window there:</p>
  
  <pre><code>class myViewModel: INotifyPropertyChanged
  {
  
      public ICommand OpenDetailsCommand
          {
              get { return new RelayCommand(OpenDetailsWindow); }
          }
  
      public void OpenDetailsWindow()
          {
              myWindow w = new myWindow();
              w.DataContext = this;
              w.Show();
          }
  </code></pre>
  
  <p>So I have no resource in this window i.e. Window.Resource</p>
  
  <p>My image is the following:</p>
  
  <pre><code>&lt;Image x:Name="myImage" 
         Source="{Binding Path=myImage}"/&gt;
  </code></pre>
  
  <p>This shows the image but I am unable to use the binding to change the image on edit.
  If I try:</p>
  
  <pre><code>&lt;Image x:Name="myImg" 
         Source="{Binding Path=myImage, Mode=TwoWay}"/&gt;
  </code></pre>
  
  <p>The binding does not work at all ... no image displayed.
  So i tired to specify the TwoWay in the Datacontext in the following way:</p>
  
  <pre><code>&lt;Image x:Name="myImg"
         DataContext="{Binding myImage, RelativeSource={RelativeSource FindAncestor, 
         AncestorType={x:Type Window}}, TwoWay}"
         Source="{Binding Path=myImage}"/&gt;
  </code></pre>
  
  <p>I tried this as a way of replicating the one that works. This also does not bind at all i.e. no image displayed.</p>
  
  <p>So I have 3 questions</p>
  
  <ol>
  <li><p>How can I get the Image to bind to the windows datacontext in a TwoWay mode.</p></li>
  <li><p>Am I doing this all wrong from the start by setting the Datacontext in the
  ViewModel?</p></li>
  <li><p>Is there a better way to pass ViewModels from window/page to window/page?</p></li>
  </ol>
  
  <p>Thank you in anticipation.</p>