title: CheckBox as datatemplate in a ListBox reset IsChecked value when scrolling
body: <p>I want to start using MVVM in my project so I have started to investigate it.
  While I was playing a bit with WPF I've encountered a bug that I couldn't find a solution to him by myself and while exploring internet.</p>
  
  <p>I have something like that(I can't paste my full code because its not in the same network):</p>
  
  <p>MainView.Xaml</p>
  
  <pre><code>&lt;ListBox ItemsSource="{Binding Persons}"&gt;
   &lt;ListBox.ItemTemplate&gt;
    &lt;DataTemplate&gt;
     &lt;CheckBox Content="{Binding Name}"&gt;
      &lt;i:Interaction.Triggers&gt;
       &lt;i:EventTrigger EventName="Checked"&gt;
          &lt;my:AddToInvitation /&gt;
       &lt;/i:EventTrigger&gt;
       &lt;i:EventTrigger EventName="Unchecked"&gt;
          &lt;my:RemoveFromInvitation /&gt;
       &lt;/i:EventTrigger&gt;
      &lt;/i:Interaction.Triggers&gt;
     &lt;/CheckBox&gt;
    &lt;/DataTemplate&gt;
  &lt;/ListBox.ItemTemplate&gt;
  </code></pre>
  
  <p></p>
  
  <p>MainViewModel.cs</p>
  
  <pre><code>public ObservableCollection&lt;PersonViewModel&gt; Persons { get; set; }
  
  public MainViewModel()
  {
    this.Persons = new ObservableCollection&lt;PersonViewModel&gt;();
    for(int i=0;i&lt;1000;i++)
    {
       PersonViewModel personVM = new PersonViewModel (string.Format("Person - {0}",i));
       this.Persons.add(personVM);
    }
  }
  </code></pre>
  
  <p>PersonViewModel.cs</p>
  
  <pre><code>private Person PersonObject { get; set; }
  
  public string Name
  {
    get
    {
       return this.PersonObject.Name;
    }
  }
  
  public PersonViewModel(string personName)
  {
    this.PersonObject = new Person(personName);
  }
  </code></pre>
  
  <p>Person.cs</p>
  
  <pre><code>public string Name { get; set; }
  
  public Person(string name)
  {
     this.Name = name;
  }
  </code></pre>
  
  <p>Now if you try to paste it and run it, it will look just fine.
  The problem is when you try the following instructions:</p>
  
  <pre><code>1) Check the first 10 persons in the ListBox.
  2) Scroll down the ListBox to the bottom of it.
  3) Leave the mouse when the list box is scrolled down.
  4) Scroll back up to the top of the ListBox.
  5) Poof! you'r checking disappeared.
  </code></pre>
  
  <p>Now the solution i have found to this is to add IsChecked property(Though I don't really need it) to the PersonViewModel and bind it to the CheckBox IsChecked DependencyProperty, but then I have added a functionality that lets the user to press a button and it will iterate over all the persons in the ListBox and change it IsChecked property to true(Button -> Select all).
  Following to the disappear Checks bug I have crossed another bug which I believe somehow is connected to the disappearing Checks - the actions that I have put to trigger when Check and Uncheck occurs would trigger only for some of the CheckBoxes when you select all.
  I tried to count how many times the actions would happen when I used the select all function and I found a connection between the height of the ListBox(Current Visible CheckBoxes) and the amount of the triggers that fired, furthermore I scrolled to the middle of the ListBox and used the SelectAll functionality and the triggers didn't fire until the loop encountered the first visible ChekBox that I can see in my ListBox.</p>
  
  <p>Its a bit hard to understand this bug if you don't try it, so please comment here only if you tried this.</p>
  
  <p>Thanks in advance!</p>