Regarding Binding in WPF RRS feed

  • Question

  • Could anyone give me brief idea about binding in WPF as I am very confused with this topic in WPF.
    Why it was introduced?
    We can easily write code for all the stuffs what binding offers then why should we use this complex binding stuff?

    Why i am asking this question because i am very much confused with binding.it would be better if some one can help with me little bit with binding so i can also start using biniding in my project.

    Thanks in advance
    Sunday, August 10, 2008 7:59 PM


  • One reason is that it's a lot more work to do in code many of the things binding will do for you. For anything but extremely trivial scenarios, "this complex binding stuff" is a lot less complex than the code you would have to write. (E.g., ensuring that your data model is updated any time the user provides data; ensuring that the screen is updated when your view changes.)

    Data templates in particular are very powerful. These make it very easy to present sets of data in powerful ways. Of course you could achieve the same results in code, but it would be more work.

    Designability is an important issue - if you put everything into the codebehind, it becomes harder to use design tools like Blend to lay out your user interface. 

    Also, data binding can help with testability: it's much easier to test code that has no direct dependency on user interface elements, because you can automate the test without needing to create the corresponding UI. Data binding can help with this, because it tends to mean the Xaml depends on your code but your code doesn't depend on the Xaml. So you can write a bunch of automated tests that just test that the various properties in your code do what they're supposed to do, without needing the Xaml to be present. 

    But in short, having been using WPF for some years now (since before it shipped), I can say that data binding saves a huge amount of effort.

    If you want a more extensive set of examples of how much work data binding can save you, the first data binding chapter of Chris Sells and my WPF book (Programming WPF by O'Reilly) has a good worked example of the benefits of data binding compare to doing it by hand.

    • Marked as answer by Marco Zhou Friday, August 15, 2008 9:46 AM
    Monday, August 11, 2008 6:31 AM