Last active
August 29, 2015 14:02
-
-
Save stefandevo/203d5491a791c3e1b67f to your computer and use it in GitHub Desktop.
Missing PropertyDescriptor value on ListChangedEventArgs with BindingList in MonoTouch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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