title: Silverlight MVVM - Twoway binding not fired on Listbox click
body: <p>In a Silverlight MVVMLight 4.0 application I have a listbox, a textbox and a checkbox.
  The listbox's ItemsSource is bound to a list of objects in the viewmodel.
  The listbox's SelectedItem is two-way bound to an object (SelectedActivity) in the viewmodel.</p>
  
  <p>Both the textbox's Text and the checkbox's IsSelected properties are two-way bound to the SelectedActivity object (Name and Selected properties) in the viewmodel.
  There is no codebehind.</p>
  
  <p>This works fine:  changing the Name in the textbox or checking/unchecking the checkbox and then tabbing will change the underlying property of the object.</p>
  
  <p>But when I change the name (or the checked state) and then immediatelly click another item in the list, the change is not registered.</p>
  
  <p>Does anybody have a workaround for this?</p>
  
  <p>kind regards,</p>
  
  <p>Karel </p>
  
  <p>This is the XAML:</p>
  
  <pre><code>&lt;ListBox Height="251" HorizontalAlignment="Left" Margin="11,39,0,0" Name="activitiesListBox" ItemsSource="{Binding Activities.Items}" VerticalAlignment="Top" Width="139"
               SelectedItem="{Binding Activities.SelectedActivity, Mode=TwoWay}"&gt;
  </code></pre>
  
  <p>This is the Activities class holding the items bound to the list:</p>
  
  <pre><code>public class CLJActivitiesViewModel : ViewModelBase
  {
      /// &lt;summary&gt;
      /// Initializes a new instance of the ActivitiesViewModel class.
      /// &lt;/summary&gt;
      public CLJActivitiesViewModel()
      {
          ////if (IsInDesignMode)
          ////{
          ////    // Code runs in Blend --&gt; create design time data.
          ////}
          ////else
          ////{
          ////    // Code runs "for real": Connect to service, etc...
          ////}
      }
  
  
      #region items
      /// &lt;summary&gt;
      /// The &lt;see cref="Items" /&gt; property's name.
      /// &lt;/summary&gt;
      public const string ItemsPropertyName = "Items";
  
      private ObservableCollection&lt;CLJActivityViewModel&gt; m_Items = null;
  
      /// &lt;summary&gt;
      /// Gets the Items property.
      /// TODO Update documentation:
      /// Changes to that property's value raise the PropertyChanged event. 
      /// This property's value is broadcasted by the Messenger's default instance when it changes.
      /// &lt;/summary&gt;
      public ObservableCollection&lt;CLJActivityViewModel&gt; Items
      {
          get
          {
              return m_Items;
          }
  
          set
          {
              if (m_Items == value)
              {
                  return;
              }
  
              var oldValue = m_Items;
              m_Items = value;
  
              RaisePropertyChanged(ItemsPropertyName, oldValue, value, true);
          }
      }
      #endregion
  
      #region SelectedActivity
      /// &lt;summary&gt;
      /// The &lt;see cref="SelectedActivity" /&gt; property's name.
      /// &lt;/summary&gt;
      public const string SelectedActivityPropertyName = "SelectedActivity";
  
      private CLJActivityViewModel m_SelectedActivity = null;
  
      /// &lt;summary&gt;
      /// Gets the SelectedActivity property.
      /// TODO Update documentation:
      /// Changes to that property's value raise the PropertyChanged event. 
      /// This property's value is broadcasted by the Messenger's default instance when it changes.
      /// &lt;/summary&gt;
      public CLJActivityViewModel SelectedActivity
      {
          get
          {
              return m_SelectedActivity;
          }
  
          set
          {
              if (m_SelectedActivity == value)
              {
                  return;
              }
  
              var oldValue = m_SelectedActivity;
              m_SelectedActivity = value;
  
              RaisePropertyChanged(SelectedActivityPropertyName, oldValue, value, true);
          }
      }
      #endregion
  
  
  
      public override void Cleanup()
      {
          // Clean own resources if needed
  
          base.Cleanup();
      }
  }        
  </code></pre>