title: Binding TwoWay to SelectedItem: "Wrong way" synchronization on initialization
body: <p>I am trying to bind a property of my <code>DataContext</code> to the <code>SelectedItem</code> on a ComboBox like this:</p>
  
  <pre><code>&lt;ComboBox x:Name="ElementSelector" 
            ItemsSource="{Binding Source={StaticResource Elements}}"
            DisplayMemberPath="ElementName"
            SelectedItem="{Binding ValueElement, Mode=TwoWay}"&gt;
  </code></pre>
  
  <p>where the <em>Elements</em> resource is a <code>CollectionViewSource</code> (don't know, whether this matters).</p>
  
  <p>When everything is initialized, the property <code>ValueElement</code> of the <code>DataContext</code> is set to the first item in the <code>CollectionViewSource</code>. What I want, is to initialize it the other way around: I would like to set <code>SelectedItem</code> of the ComboBox to the value of the property or null if no matching item is contained.</p>
  
  <p>How can this be done? </p>
  
  <p><strong>EDIT - Additional information:</strong></p>
  
  <p>The ComboBox is part of a DataTemplate:</p>
  
  <pre><code>&lt;DataTemplate x:Key="ReferenceTemplate" 
                DataType="viewModels:ElementMetaReferenceViewModel"&gt;
     &lt;StackPanel Orientation="Horizontal"&gt;
        &lt;StackPanel.Resources&gt;
           &lt;ResourceDictionary&gt;
              &lt;views:ElementsForReferenceViewSource x:Key="Elements" 
                                                    Source="{Binding  DataContext.CurrentProject.Elements, ElementName=Root}" 
                                                    ReferenceToFilterFor="{Binding}"/&gt;
           &lt;/ResourceDictionary&gt;
        &lt;/StackPanel.Resources&gt;
  
        &lt;TextBlock Text="{Binding PropertyName}"/&gt;
        &lt;ComboBox x:Name="ElementSelector" 
                  ItemsSource="{Binding Source={StaticResource Elements}}"
                  DisplayMemberPath="ElementName" 
                  SelectedItem=""{Binding ValueElement, Mode=TwoWay}" /&gt;
  
     &lt;/StackPanel&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>The <code>ElementsForReferenceViewSource</code> simply derives from <code>CollectionViewSource</code> and implements an additional DependencyProperty which is used for filtering.</p>
  
  <p>The <code>DataContext</code> of the items in the <code>CollectionViewSource</code> look like this:</p>
  
  <pre><code>public class ElementMetaReferenceViewModel : ViewModelBase&lt;ElementMetaReference, ElementMetaReferenceContext&gt;
  {
     ...
      private ElementMetaViewModel _valueElement;
  
      public ElementMetaViewModel ValueElement
      {
          get { return _valueElement; }
          set
          {
              if (value == null) return;
              _valueElement = value;
              Model.TargetElement = value.Model;
          }
      }
  
      ...
  }
  </code></pre>