title: Call Function in Parent Window from Child Window
body: <p>I'm attempting to implement a custom search dialog in a WPF program. The Parent window is a ListView that is bound to an Observable Collection.</p>
  
  <p>I've made a new window with the search form and it is initialized like so:</p>
  
  <pre><code>searchForm sf = new searchForm(_QPCollection);
  sf.Owner = this;
  sf.Show();
  </code></pre>
  
  <p>and I have this function I am trying to call (in the Owner window):</p>
  
  <pre><code>public void selectIndex(int index)
  {
      ListViewItem toSelect = listView1.Items[index] as ListViewItem;
      toSelect.Focus();
  }
  </code></pre>
  
  <p>Then in the Child window (searchForm) attempting to call selectIndex like so:</p>
  
  <pre><code>public void SearchJob_Click(object sender, RoutedEventArgs e)
  {
      if (sJob.Text == "" || sJob.Text == null) { return; }
      for (int i = findCount; i &lt; _QPCollectionSearch.Count; i++)
      {
          if (i == _QPCollectionSearch.Count - 1) { i = 0; }
          if (_QPCollectionSearch[i].jobNumAndFlow.IndexOf(sJob.Text) &gt; -1)
          {
              findCount = i;
              Owner.selectIndex(i);
          }
  
      }
  }
  </code></pre>
  
  <p>I get the error: System.Windows.Window does not contain a definition for "selectIndex".</p>
  
  <p>The <code>_QPCollection</code> is the observable collection that the search will loop through. I have the search logic working, but I cannot seem <code>Focus()</code> the index of the ListView in the Parent Window.</p>
  
  <p>My first thought was to have a public function that I could pass the index to and it would do the focus, but I cannot seem to find a way to call function from the Child Window that are in the Parent Window.</p>
  
  <p>Am I approaching this completely wrong? This <a href="https://stackoverflow.com/questions/4160396/how-to-access-and-change-value-of-parent-window-control-from-child-window-in-c">answer</a> seems to be for WinForms but I am sure there is a way to access the Parent Window and its public functions/properties in WPF.</p>