title: How to implement next-previous buttons for images?
body: <p>I tried to implement a simple next-previous image preview with two buttons but the code below works only for 3 images. How to make it more dynamic for any number of images? I would appreciate any help.</p>
  
  <pre><code>private void left_arrow_btn_Click(object sender, RoutedEventArgs e)
  {
      if (x == custom_studio_images.Count - 2)
      {
          x = custom_studio_images.Count;
          //System.Windows.MessageBox.Show(x.ToString());
          CustomStudio.Children.RemoveAt(LargePic.Children.Count);
          CustomStudio.Children.Add(custom_studio_images.ElementAt(x - 1));
  
      }
  
      else
      {
          CustomStudio.Children.RemoveAt(LargePic.Children.Count);
          CustomStudio.Children.Add(custom_studio_images.ElementAt(x - 2));
          //System.Windows.MessageBox.Show(x.ToString());
  
          x--;
      }
  }
  
  private void right_arrow_btn_Click(object sender, RoutedEventArgs e) 
  {
      if (CustomStudio.Children.Count &gt; 0)
      {
          CustomStudio.Children.RemoveAt(LargePic.Children.Count); //clear first item in StackPanel
      }
  
  
      if (x == custom_studio_images.Count )
      {
          x = 0;
          CustomStudio.Children.Add(custom_studio_images.ElementAt(x));
          x++;
      }
  
  
      else
      {
          CustomStudio.Children.Add(custom_studio_images.ElementAt(x)); //show picture for next available studio in a set
          x++;
  
      }
  
  }
  </code></pre>