title: How to trim text displayed in a ComboBox?
body: <p>I have my own combobox (autocompleteCombobox) where I would like to see only 35 characters of the selectedItem, but with a tooltip that show the full name.</p>
  
  <p>The user control code:</p>
  
  <pre><code>&lt;UserControl.Resources&gt;
      &lt;Style x:Key="ComboboxStyle" TargetType="{x:Type ComboBox}"&gt;
          &lt;Setter Property="ItemTemplate"&gt;
              &lt;Setter.Value&gt;
                  &lt;DataTemplate&gt;
                      &lt;TextBlock Text="{Binding ShownName}"/&gt;
                  &lt;/DataTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
  &lt;/UserControl.Resources&gt;
  &lt;Grid&gt;
      &lt;ComboBox x:Name="Combobox" IsSynchronizedWithCurrentItem="True" 
                IsEditable="True" TextSearch.Text="ShownName"
                IsTextSearchEnabled="True" DisplayMemberPath="ShownName"
                ToolTip="{Binding SelectedItem.ShownName,ElementName=autoComplete}"
                ItemsSource="{Binding ItemsSource,ElementName=autoComplete}"
                SelectedItem="{Binding SelectedItem, ElementName=autoComplete}"
                Style="{StaticResource ComboboxStyle}"&gt;
          &lt;ComboBox.InputBindings&gt;
              &lt;KeyBinding Key="Enter"
                          Command="{Binding Path=SelectItemCommand, ElementName=autoComplete}"
                          CommandParameter="ShownName"/&gt;
          &lt;/ComboBox.InputBindings&gt;
      &lt;/ComboBox&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>And inside the cs file of the autocompletecombobox:</p>
  
  <pre><code>public static readonly DependencyProperty MaxTextLengthProperty =
          DependencyProperty.Register(
              "MaxTextLength",
              typeof(int),
              typeof(ComboBoxAutoComplete),
              new UIPropertyMetadata(35));
          public int MaxTextLength
          {
              get { return (int)GetValue(MaxTextLengthProperty); }
              set
              {
                  SetValue(MaxTextLengthProperty, value);
                  LimitTextInCombobox();
              }
          }
  
          private void LimitTextInCombobox()
          {
              Combobox.Text = Combobox.Text.Substring(0, MaxTextLength);   
          }    
  </code></pre>
  
  <p>But it doesn't work...</p>