title: WPF Combobox with clear button
body: <p>I am trying to create a WPF ComboBox control which contains a clear button when something is selected. The control should have two states: if something is selected the control looks like a label with a clear button. If nothing is select then a normal ComboBox is display. The two states are showing  in the picture below.</p>
  
  <p><img src="https://i.stack.imgur.com/OJKT2.jpg" alt="enter image description here"></p>
  
  <p>Researching my problem I came across the following SO questions which are very similar to mine:</p>
  
  <p><a href="https://stackoverflow.com/questions/2807481/adding-a-button-to-a-combobox-in-wpf">Adding a button to a combobox in wpf</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3515125/how-to-subclass-a-wpf-combobox-to-add-an-extra-button">How to subclass a WPF ComboBox to add an extra button</a></p>
  
  <p>Both suggest subclassing the ComboBox providing a modified template with the extra button. But this is where I am a tad confused. The answer by John Bowen to the second linked question indicates that I should copy the ComboBox's default template; modifying it to include a button getting the template from Blend. Not being proficient with blend I found the template on MSDN here: </p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/ms752094(v=vs.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms752094(v=vs.85).aspx</a></p>
  
  <p>My problem is I am not quite sure what I should change. Looking at the Default template I think I need to do something along the lines of:</p>
  
  <ul>
  <li>Create a new 'IsSelected' property which I can hook triggers to. </li>
  <li>Add a control template for a Clear Button with trigger attached to IsSelected which hides the button.</li>
  <li>Attached a IsSelected Trigger to the ComboBoxToggleButton control template to hide it upon selection.</li>
  <li>Somehow re-size the <code>PART_EditableTextBox</code> textbox in the ComboBox Template when IsSelected is true.</li>
  </ul>
  
  <p>Does this seem right and any pointers on how I do it or other suggestions if I am barking up the wrong tree.</p>