title: Custom combobox selected text within wpf application
body: <p>I have a wpf application , in which I have this problem :</p>
  
  <pre><code>    &lt;UserControl.Resources&gt;
                  &lt;ItemsPanelTemplate x:Key="VSP"&gt;
                      &lt;VirtualizingStackPanel 
                          VirtualizingPanel.CacheLength="20"
                          VirtualizingPanel.ScrollUnit="Item"
                          VirtualizingPanel.VirtualizationMode="Recycling"
                          VirtualizingPanel.IsVirtualizing="True"/&gt;
                  &lt;/ItemsPanelTemplate&gt;
                  &lt;DataTemplate x:Key="ExpertTemplate"&gt;
                      &lt;Grid Width="640"&gt;
                          &lt;Grid.ColumnDefinitions&gt;
                              &lt;ColumnDefinition Width="160"/&gt;
                              &lt;ColumnDefinition Width="160"/&gt;
                              &lt;ColumnDefinition Width="160" /&gt;
                              &lt;ColumnDefinition Width="160"/&gt;
                          &lt;/Grid.ColumnDefinitions&gt;
                          &lt;Label Content="{Binding fsign_id}" Grid.Column="0"   /&gt;
                          &lt;Label Content="{Binding fsign_civilite}" Grid.Column="1" /&gt;
                          &lt;Label Content="{Binding fsign_nom}" Grid.Column="2"  /&gt;
                          &lt;Label Content="{Binding fsign_prenom}" Grid.Column="3"  /&gt;
                      &lt;/Grid&gt;
                  &lt;/DataTemplate&gt;
              &lt;/UserControl.Resources&gt;
          .............
           &lt;DataGrid x:Name="grid"  ItemsSource="{Binding Entitites}" SelectedValue="{Binding SelectedValue}"   &gt;
                  &lt;DataGrid.Resources&gt;
                                  &lt;Style TargetType="DataGridCell"&gt;
                                      &lt;Setter Property="HorizontalAlignment" Value="Center" /&gt;
                                  &lt;/Style&gt;
                   &lt;/DataGrid.Resources&gt;
                   &lt;DataGrid.Columns&gt;
                                    &lt;DataGridTemplateColumn Header="Participant" Width="200"&gt;
                                      &lt;DataGridTemplateColumn.CellTemplate&gt;
                                          &lt;DataTemplate&gt;
                                              &lt;skin:ParticipantExpert  SelectedValue="{Binding SelectedElement, Mode=TwoWay,  UpdateSourceTrigger=LostFocus}"  ItemsPanel="{StaticResource VSP}"  ItemTemplate="{DynamicResource ExpertTemplate }"   Width="220"      ItemsSource="{Binding ExpertCollection}"  &gt;
  
                                              &lt;/skin:ParticipantExpert&gt;
                                          &lt;/DataTemplate&gt;
                                      &lt;/DataGridTemplateColumn.CellTemplate&gt;
                                  &lt;/DataGridTemplateColumn&gt;
                    &lt;/DataGrid.Columns&gt;
          &lt;/DataGrid&gt;
  </code></pre>
  
  <p>the customized combobox :</p>
  
  <pre><code> public class ParticipantExpert : ComboBox 
      {
  
          public ParticipantExpert()
          {
  
          } 
          protected override void OnSelectionChanged(SelectionChangedEventArgs e)
          {
              if (SelectedItem == null) { return; }
              vue_groupe_participant CurrentItem = (vue_groupe_participant)SelectedItem;
              Text = CurrentItem.fsign_nom + "   " + CurrentItem.fsign_prenom;
          }
  
      }
  </code></pre>
  
  <p>I put a breakpoint in this line <code>if (SelectedItem == null) { return; }</code> . When I select an element from the combobox the event is raised twice !! The first one <code>SelectedItem</code> is the selected object but in the second one it takes null as value.</p>
  
  <p>So I need to know :</p>
  
  <ol>
  <li>Why the event is raised two times?</li>
  <li>How can I fix my code ?</li>
  </ol>
  
  <p>Thanks,</p>