title: How to update the draw order of a list of controls in WPF
body: <p>I made a custom WPF editor and I am having trouble getting a list of screen control objects (buttons, text boxes, etc) to be displayed in the correct draw order. Here is a visual of my current setup:</p>
  
  <p><a href="https://i.stack.imgur.com/0gdca.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0gdca.png" alt="enter image description here"></a></p>
  
  <p>I have the control object window working just fine and I can see when the list is changed.</p>
  
  <p>My problem is this: Say that I selected object 3 and pressed the up button. The object should move up in the list (which it does!) BUT the draw order stays the same. Meaning that object 3 should draw behind object 2 and its not doing that. I don't know why. </p>
  
  <p>Here is my code: </p>
  
  <pre><code>    private void MoveUp_Click(object sender, RoutedEventArgs e)
      {
        for (int i = 0; i &lt; controlObjectList.Count; i++)
        {
          if (controlObjectList[i].IsSelected)
          {          
            // Copy the current item
            var selectedItem = controlObjectList[i];
            int newindex = Math.Abs(i - 1);
  
            // Remove the item
            controlObjectList.RemoveAt(i);
  
            // Finally add the item at the new index
            controlObjectList.Insert(newindex, selectedItem);
          }
        }
        RefreshControlObjectList(controlObjectList);
      }
  
      private void MoveDown_Click(object sender, RoutedEventArgs e)
      {
        for (int i = 0; i &lt; screenDesigner.m_ParentScreenObject.controlObjects.Count; i++)
        {
          if (controlObjectList[i].IsSelected)
          {
            // Copy the current item
            var selectedItem = controlObjectList[i];
            int newindex = i + 1;
  
            if(newindex &lt; controlObjectList.Count)
            {
              // Remove the item
              controlObjectList.RemoveAt(i);
  
              // Finally add the item at the new index
              controlObjectList.Insert(newindex, selectedItem);
            }          
          }
        }
        RefreshControlObjectList(controlObjectList);
      }
  
      private void RefreshControlObjectList(List&lt;ItemsList&gt; newList)
      {
        newList.Items.Clear();
        foreach (ItemsList il in controlObjectList)
        {
          listObjects.Items.Add(il);
        }
        //I know this is where I should place the logic for the draw order...
      }
      #endregion
    }
  </code></pre>
  
  <p>What I'm trying to figure out is how can I refresh the screen in order to see the correct draw order of my objects? Is it possible? Many thanks in advance!</p>