title: programmatically select next listbox item
body: <p>I'm trying to program two buttons to imitate the up/down arrow key behavior, meaning that when I press the button for up, it moves up one item in my listbox and so on. I wrote the following code:</p>
  
  <pre><code>private void mainlistup(object sender, System.Windows.RoutedEventArgs e)
  {
      if (listBox_Copy.SelectedIndex != -1 &amp;&amp;
          listBox_Copy.SelectedIndex &lt; listBox_Copy.Items.Count &amp;&amp;
          listBox_Copy.SelectedIndex !=1)
      {
          listBox_Copy.SelectedIndex = listBox_Copy.SelectedIndex - 1;
      }
  }
  
  private void mainlistdown(object sender, System.Windows.RoutedEventArgs e)
  {
      if (listBox_Copy.SelectedIndex &lt; listBox_Copy.Items.Count &amp;&amp;
         listBox_Copy.SelectedIndex != -1)
      {
          listBox_Copy.SelectedIndex = listBox_Copy.SelectedIndex + 1;
      }
  }
  </code></pre>
  
  <p>This works, however, when pressing the button the item loses its selection... The selection index is set properly (other databinded items, binded to selected item show the correct values) but the listbox item isn't highlighted anymore. How do I set the selected item to become highlighted?</p>