Skip to content

Instantly share code, notes, and snippets.

@stefandevo
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stefandevo/203d5491a791c3e1b67f to your computer and use it in GitHub Desktop.
Save stefandevo/203d5491a791c3e1b67f to your computer and use it in GitHub Desktop.
Missing PropertyDescriptor value on ListChangedEventArgs with BindingList in MonoTouch
using System;
using NUnit.Framework;
using System.ComponentModel;
namespace BindingListBug
{
[TestFixture]
public class BindingListBugTest
{
string changedPropertyName = string.Empty;
bool isEventRaised = false;
[SetUp]
public void SetUp ()
{
var persons = new BindingList<Person> ();
persons.Add (new Person (){ FirstName = "Stefaan", LastName = "de Vogelaere" });
persons.Add (new Person (){ FirstName = "Christophe", LastName = "De Langhe" });
persons.ListChanged += (object sender, ListChangedEventArgs e) => {
isEventRaised = true;
if (e.PropertyDescriptor != null)
changedPropertyName = e.PropertyDescriptor.Name;
};
persons [0].FirstName = "Stefan";
}
[Test]
public void IsEventRaised ()
{
Assert.IsTrue (isEventRaised);
}
[Test]
public void DidWeReceiveChangedPropertyName ()
{
Assert.AreEqual ("FirstName", changedPropertyName);
}
}
public class Person : INotifyPropertyChanged
{
private string _lastName;
private string _firstName;
public string FirstName {
get { return _firstName; }
set {
_firstName = value;
OnPropertyChanged ("FirstName");
}
}
public string LastName {
get { return _lastName; }
set {
_lastName = value;
OnPropertyChanged ("LastName");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged (string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler (this, new PropertyChangedEventArgs (propertyName));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment