title: Dynamically changing contents of a WPF dropdown
body: <p>So I have these 2 dropdown boxes that should have a linked behaviour.
  For example: When changing the content of the first dropdown, the content of the second should change dynamically. </p>
  
  <pre><code>&lt;ComboBox x:Name="ServerCombo"
            Loaded="Servers_ComboBox_Loaded"
            DropDownClosed="Servers_ComboBox_DropDownClosed"
            SelectionChanged="ServerCombo_SelectionChanged" /&gt;
  &lt;ComboBox x:Name="BuildCombo"
            SelectionChanged="Builds_ComboBox_SelectionChanged"
            Loaded="Builds_ComboBox_Loaded"
            DropDownClosed="Builds_ComboBox_DropDownClosed" /&gt;
  </code></pre>
  
  <p>So picking a different Server will trigger the BuildCombo box to have different values.
  This is the current code (a bit messy, sorry):</p>
  
  <pre><code>  public MainWindow()
      {
          InitializeComponent();
      }
  
  
  
      public void ScanBuilds(object sender, RoutedEventArgs e)
      {
          var dialog = new System.Windows.Forms.FolderBrowserDialog();
          hubBuildsList(hubPath);
      }
  
      public List&lt;string&gt; hubBuildsList(string hubPath)
      {
          string[] sDirectories = Directory.GetDirectories(hubPath);
          List&lt;string&gt; lDirectories = new List&lt;string&gt;();
          for (int i = 0; i &lt; sDirectories.Length; i++)
          {
              string sDirectory = sDirectories[i];
              sDirectory = sDirectory.Substring(sDirectory.LastIndexOf(@"\")).Remove(0,1);
              lDirectories.Add(sDirectory);
          }
          return lDirectories;
      }
  
      public List&lt;string&gt; ServersList()
      {
          List&lt;string&gt; lServersList = new List&lt;string&gt;();
          lServersList.Add("qa02");
          lServersList.Add("qa03");
          lServersList.Add("qa04");
          return lServersList;
      }
  
      public void MoveBuild(string sSelectedBuild)
      {
          string a = sSelectedBuild;
          string sBuildToMove = hubPath + "\\" +  sSelectedBuild;
          string sDestinationPath = hubInstallationPath + "\\" + sSelectedBuild;
          Directory.CreateDirectory(sDestinationPath);
          DirectoryCopy(sBuildToMove, sDestinationPath);
  
      }
  
      private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs = true)
      {
          // Get the subdirectories for the specified directory.
          DirectoryInfo dir = new DirectoryInfo(sourceDirName);
  
          if (!dir.Exists)
          {
              throw new DirectoryNotFoundException(
                  "Source directory does not exist or could not be found: "
                  + sourceDirName);
          }
  
          DirectoryInfo[] dirs = dir.GetDirectories();
          // If the destination directory doesn't exist, create it.
          if (!Directory.Exists(destDirName))
          {
              Directory.CreateDirectory(destDirName);
          }
  
          // Get the files in the directory and copy them to the new location.
          FileInfo[] files = dir.GetFiles();
          foreach (FileInfo file in files)
          {
              string temppath = System.IO.Path.Combine(destDirName, file.Name);
              file.CopyTo(temppath, false);
          }
  
          // If copying subdirectories, copy them and their contents to new location.
          if (copySubDirs)
          {
              foreach (DirectoryInfo subdir in dirs)
              {
                  string temppath = System.IO.Path.Combine(destDirName, subdir.Name);
                  DirectoryCopy(subdir.FullName, temppath, copySubDirs);
              }
          }
      }
  
      private void hub_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
      {
  
      }
  
      private void hubCombo_DropDownClosed(object sender, EventArgs e)
      {
          sSelectedhub = (string)(hubCombo.SelectedItem);
      }
  
      private void hub_ComboBox_Loaded(object sender, RoutedEventArgs e)
      {
          List&lt;string&gt; data = hubBuildsList(hubPath);
          var comboBox = sender as ComboBox;
          comboBox.ItemsSource = data;
          comboBox.SelectedIndex = 0;
      }
  
  
      private void Servers_ComboBox_DropDownClosed(object sender, EventArgs e)
      {
  
      }
  
      private void Install_Button_Click(object sender, RoutedEventArgs e)
      {
          MoveBuild(sSelectedhub);
  
      }
  
      private void Servers_ComboBox_Loaded(object sender, RoutedEventArgs e)
      {
          List&lt;string&gt; data = ServersList();
          var comboBox = sender as ComboBox;
          comboBox.ItemsSource = data;
          comboBox.SelectedIndex = 0;
      }
  
      private void Builds_ComboBox_DropDownClosed(object sender, EventArgs e)
      {
          sSelectedServer = (string)(ServerCombo.SelectedItem);
          List&lt;string&gt; data = BuildsList(sSelectedServer);
          //List&lt;string&gt; data = ServersList();
          var comboBox = sender as ComboBox;
          comboBox.ItemsSource = data;
          comboBox.SelectedIndex = 0;
          //BuildCombo.SelectedIndex = BuildCombo.FindStringExact("test1");
          //BuildCombo.text = "test1";
      }
  
      private List&lt;string&gt; BuildsList(string sServer)
      {
          string[] sDirectories = Directory.GetDirectories(sServer);
          List&lt;string&gt; lBuildsList = new List&lt;string&gt;();
  
          for (int i = 0; i &lt; sDirectories.Length; i++)
          {
              string sDirectory = sDirectories[i];
              sDirectory = sDirectory.Substring(sDirectory.LastIndexOf(@"\")).Remove(0, 1);
              lBuildsList.Add(sDirectory);
          }
  
          lBuildsList.Add("qa02");
          return lBuildsList;
      }
  
      private void Builds_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
      {
  
      }
  
      private void Builds_ComboBox_Loaded(object sender, RoutedEventArgs e)
      {
          sSelectedServer = (string)(ServerCombo.SelectedItem);
          List&lt;string&gt; data = BuildsList(sSelectedServer);
          var comboBox = sender as ComboBox;
          comboBox.ItemsSource = data;
          comboBox.SelectedIndex = 0;
      }
  
      private void ServerCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
      {
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks!</p>