Learning through teaching

Learning through teaching

data: 9 grudnia, 2013
czas czytania: 2 min
autor: Maciej Wrześniowski

That’s a true story. This conversation between me and a new member of my team happened when I was introducing him to the world of WPF. For the purpose of this text, let’s call him Zenon.

Zenon: hey, bindings ignore private property setters and just use them.

Me: ? – I approach his computer, debug and can’t believe what I see. I return to my computer, create some simple application (because I bet his computer is broken or sth). I can’t believe even more. Strange… Uncle Google. Whew – it was a load off my mind. Error in .NET 4.5! Here are the details:

public class Person
{
    private string _name;
    public string Name
    {
        get { return _name; }
        private set
        {
            if (_name == value)
            {
                return;
            }
            _name = value;
        }
     }
}

For such a defined class TwoWay Binding respects setter’s privacy and an exception is just thrown – perfectly, but:

public class Person : NotificationObject
{
    private string _name;
    public string Name
    {
        get { return _name; }
        private set
        {
            if (_name == value)
            {
                return;
            }
            _name = value;
            RaisePropertyChanged(...);
        }
    }
}

Here Mr Binding is doing what he wants – error concerns a different Binding interpretation of objects implementing INotifyPropertyChanged (in our case, from Prism) and those which don’t implement them.

Thanks Zenon!

Newsletter IT leaks

Dzielimy się inspiracjami i nowinkami z branży IT. Szanujemy Twój czas - obiecujemy nie spamować i wysyłać wiadomości raz na dwa miesiące.

Subscribe to our newsletter

Administratorem Twoich danych osobowych jest Future Processing S.A. z siedzibą w Gliwicach. Twoje dane będziemy przetwarzać w celu przesyłania cyklicznego newslettera dot. branży IT. W każdej chwili możesz się wypisać lub edytować swoje dane. Więcej informacji znajdziesz w naszej polityce prywatności.

Subscribe to our newsletter

Administratorem Twoich danych osobowych jest Future Processing S.A. z siedzibą w Gliwicach. Twoje dane będziemy przetwarzać w celu przesyłania cyklicznego newslettera dot. branży IT. W każdej chwili możesz się wypisać lub edytować swoje dane. Więcej informacji znajdziesz w naszej polityce prywatności.