title: how to show selected text in combobox using custom template
body: <p>I'm new in WPF, implementing application to show 2 combobox with different formated text.</p>
  
  <p>I have created custom controltemplate for combobox </p>
  
  <pre><code>&lt;ControlTemplate x:Key="GridGenreComboboxTemplate" TargetType="{x:Type ComboBox}"&gt;
              &lt;ControlTemplate.Resources&gt;
                  &lt;SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/&gt;
                  &lt;SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/&gt;
              &lt;/ControlTemplate.Resources&gt;
              &lt;StackPanel&gt;
                  &lt;ToggleButton  
                                    IsTabStop="False" x:Name="DropDownToggle"
                                    HorizontalContentAlignment="Left" 
                                    IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"&gt;
  
                      &lt;ContentPresenter Content="{TemplateBinding SelectedItem}" 
                                    ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" 
                                    Margin="10,4" 
                                    VerticalAlignment="Center"
                                    HorizontalAlignment="Left"&gt;
                          &lt;ContentPresenter.Resources&gt;
                              &lt;Style TargetType="{x:Type TextBlock}"&gt;
                                  &lt;Setter Property="Foreground" Value="{Binding Path=Foreground,RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}"/&gt;
  
                              &lt;/Style&gt;
                          &lt;/ContentPresenter.Resources&gt;
                          &lt;ContentPresenter.ContentTemplate&gt;
                              &lt;DataTemplate&gt;
                                  &lt;TextBlock Text ="{Binding}"&gt;&lt;/TextBlock&gt;
                              &lt;/DataTemplate&gt;
                          &lt;/ContentPresenter.ContentTemplate&gt;
                      &lt;/ContentPresenter&gt;
  
                  &lt;/ToggleButton&gt;
  
  
                  &lt;!-- Popup for dropdown when combobox is clicked and open --&gt;
                  &lt;Popup x:Name="PART_Popup" AllowsTransparency="True"
                             Width="{Binding Path=ActualWidth, RelativeSource={RelativeSource TemplatedParent}}"
                             Placement="Bottom" IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" 
                             PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"&gt;
                      &lt;Grid MaxHeight="{TemplateBinding MaxDropDownHeight}"&gt;
                          &lt;Border x:Name="Splitter" BorderThickness="0,3,0,0"&gt;
                              &lt;Border.BorderBrush&gt;
                                  &lt;SolidColorBrush&gt;
                                      &lt;SolidColorBrush.Color&gt;
                                          &lt;Color R="58" G="64" B="70" A="255"/&gt;
                                      &lt;/SolidColorBrush.Color&gt;
                                  &lt;/SolidColorBrush&gt;
                              &lt;/Border.BorderBrush&gt;
                          &lt;/Border&gt;
  
                          &lt;Grid Margin="0,3,0,0"&gt;
                              &lt;Border CornerRadius="0,0,2,2" BorderThickness="1,0,1,1" x:Name="DropDownBorder"
                                  Background="Green"&gt;
                                  &lt;Border.BorderBrush&gt;
                                      &lt;SolidColorBrush Opacity="0.9"&gt;
                                          &lt;SolidColorBrush.Color&gt;
                                              &lt;Color R="96" G="96" B="97" A="255"/&gt;
                                          &lt;/SolidColorBrush.Color&gt;
                                      &lt;/SolidColorBrush&gt;
                                  &lt;/Border.BorderBrush&gt;
                              &lt;/Border&gt;
  
                              &lt;ScrollViewer CanContentScroll="true" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"&gt;
                                  &lt;ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" x:Name="Content"
                                                      KeyboardNavigation.DirectionalNavigation="Continue"  HorizontalAlignment="Stretch"/&gt;
                              &lt;/ScrollViewer&gt;
                          &lt;/Grid&gt;
                      &lt;/Grid&gt;
                  &lt;/Popup&gt;
              &lt;/StackPanel&gt;
          &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>in one combobox want to show formated text i.e. 1000 x 900, 200 x 300,.. and in another want to show
  text like 1000 900 topology, 200 300 topology</p>
  
  <p>I have formated combobox item and it shows correct value but selected value doesn't show on combobox.
  how to do this using single combobox item template?</p>
  
  <pre><code>    &lt;ComboBox Grid.Row="0"   ItemsSource="{Binding PossibleTopologysNew}"
                           SelectedItem="{Binding SelectedTopologyNew}"             
                        Template="{StaticResource GridGenreComboboxTemplate}"  
                        &gt;
              &lt;ComboBox.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                          &lt;TextBlock  Margin="10"&gt;
                              &lt;TextBlock.Text&gt;
                                  &lt;MultiBinding StringFormat="{}{0} x {1}"&gt;
                                      &lt;Binding Path="LeftNumber"/&gt;
                                      &lt;Binding Path="RightNumber"/&gt;
                                  &lt;/MultiBinding&gt;
                              &lt;/TextBlock.Text&gt;
                          &lt;/TextBlock&gt;
  
                      &lt;/DataTemplate&gt;
              &lt;/ComboBox.ItemTemplate&gt;
              &lt;/ComboBox&gt;
  
   &lt;ComboBox Grid.Row="0"   ItemsSource="{Binding PossibleTopologysNew}"
                           SelectedItem="{Binding SelectedTopologyNew}"             
                        Template="{StaticResource GridGenreComboboxTemplate}"  
                        &gt;
              &lt;ComboBox.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                          &lt;TextBlock  Margin="10"&gt;
                              &lt;TextBlock.Text&gt;
                                  &lt;MultiBinding StringFormat="{}{0}  {1} topology"&gt;
                                      &lt;Binding Path="LeftNumber"/&gt;
                                      &lt;Binding Path="RightNumber"/&gt;
                                  &lt;/MultiBinding&gt;
                              &lt;/TextBlock.Text&gt;
                          &lt;/TextBlock&gt;
  
                      &lt;/DataTemplate&gt;
              &lt;/ComboBox.ItemTemplate&gt;
              &lt;/ComboBox&gt;
  </code></pre>