locked
Data Binding in WPF compare to Windows Forms RRS feed

  • Question

  • Hi,

    I tried to find out, but could not find exact details.

    I want to know what are the features related to data binding, which are available in WPF but not in windows Forms.

    I know, data binding is easier in WPF, but right now I want to understand the scenarios, where Windows Forms data binding is not useful, but WPF will work.

    If you can give example, that will be great.

    Thanks

    Niket

    Friday, May 14, 2010 4:41 AM

Answers

  • Hi,

    I think the main advantage of WPF over Windows Forms is not data binding, but data templating: the type of the data can determine the UI that is instantiated, and this UI can be defined in a concise, easy, declarative way using XAML. This takes polymorphic behaviour to the UI level, without the need to implement custom frameworks for dynamic UI generation.

    Personally, I like the loose coupling between the UI and the business layer which is enforced when using WPF and the MVVM pattern. While in Windows Forms, data binding is optional, in WPF it is the main mechanism to connect the UI layer to what is below it, and if one uses the Model-View-ViewModel pattern, it effectively becomes the only mechanism. This forces one to think very clearly about what the application can do, allows to change the UI without any side effects in the lower layers, and allows to test the application independent of the UI.


    http://wpfglue.wordpress.com
    • Marked as answer by Aland Li Tuesday, May 25, 2010 8:43 AM
    Monday, May 24, 2010 6:23 PM
  • Hi Niketrk,

    Actually there are so many differences between WPF data binding and WinForm binding, but some concepts are similar. Below are some items I know:

    1. To enable binding notifing.
    WinForm: single object: INotifyPropertyChanged; collection: IBindingList.
    WPF: single object: INotifyPropertyChanged; collection: INotifyCollectionChanged.

    2. Mediator of binding:
    WinForm: BindingSource.
    WPF: CollectionView

    3. The common property of a control which is used to bind a data source:
    WinForm: DataSource;
    WPF: ItemsSource;

    I just mention some of the differences. To get details, you need to read the documents below:
    WinForm: http://msdn.microsoft.com/en-us/library/ef2xyb33.aspx
    WPF: http://msdn.microsoft.com/en-us/library/ms750612(v=VS.100).aspx

    Let me know if this does not help.
    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    • Marked as answer by Aland Li Sunday, May 23, 2010 7:56 AM
    • Unmarked as answer by Niketrk Monday, May 24, 2010 2:47 PM
    • Proposed as answer by Bharat Reddy - MCP, MCAD,MSTS Monday, May 24, 2010 3:08 PM
    • Marked as answer by Aland Li Tuesday, May 25, 2010 8:43 AM
    • Unmarked as answer by Aland Li Tuesday, May 25, 2010 8:43 AM
    • Marked as answer by Aland Li Tuesday, May 25, 2010 8:43 AM
    Wednesday, May 19, 2010 1:07 PM
  • The binding is much more flexible than winforms binding.

    One of the first little applications I wrote in WPF was a clock.  The hands are rectangles whose rotation is controlled by binding.

    You can bind things you wouldn't think of doing in winforms.

    I have a form which has two controls above one another.  The top one is a datagrid and the bottom one a treegrid.  I have the column widths of the treegrid bound to those of the datagrid.  As you resize the screen all the columns resize proportionately.  This is all done in xaml.

     

    • Marked as answer by Aland Li Tuesday, May 25, 2010 8:43 AM
    Monday, May 24, 2010 7:21 PM

All replies

  • Hi Niketrk,

    Actually there are so many differences between WPF data binding and WinForm binding, but some concepts are similar. Below are some items I know:

    1. To enable binding notifing.
    WinForm: single object: INotifyPropertyChanged; collection: IBindingList.
    WPF: single object: INotifyPropertyChanged; collection: INotifyCollectionChanged.

    2. Mediator of binding:
    WinForm: BindingSource.
    WPF: CollectionView

    3. The common property of a control which is used to bind a data source:
    WinForm: DataSource;
    WPF: ItemsSource;

    I just mention some of the differences. To get details, you need to read the documents below:
    WinForm: http://msdn.microsoft.com/en-us/library/ef2xyb33.aspx
    WPF: http://msdn.microsoft.com/en-us/library/ms750612(v=VS.100).aspx

    Let me know if this does not help.
    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    • Marked as answer by Aland Li Sunday, May 23, 2010 7:56 AM
    • Unmarked as answer by Niketrk Monday, May 24, 2010 2:47 PM
    • Proposed as answer by Bharat Reddy - MCP, MCAD,MSTS Monday, May 24, 2010 3:08 PM
    • Marked as answer by Aland Li Tuesday, May 25, 2010 8:43 AM
    • Unmarked as answer by Aland Li Tuesday, May 25, 2010 8:43 AM
    • Marked as answer by Aland Li Tuesday, May 25, 2010 8:43 AM
    Wednesday, May 19, 2010 1:07 PM
  • Hi Aland,

    Thanks for those links, and I will look into them.

    I want to understand/find the scenarios where winforms data binding will not work, but WPF will do.

    What you have mentioned is "differences at syntex level". I am finding it from application requirement point of view.

    Regards

    Niket

    Monday, May 24, 2010 2:51 PM
  • Hi,

    I think the main advantage of WPF over Windows Forms is not data binding, but data templating: the type of the data can determine the UI that is instantiated, and this UI can be defined in a concise, easy, declarative way using XAML. This takes polymorphic behaviour to the UI level, without the need to implement custom frameworks for dynamic UI generation.

    Personally, I like the loose coupling between the UI and the business layer which is enforced when using WPF and the MVVM pattern. While in Windows Forms, data binding is optional, in WPF it is the main mechanism to connect the UI layer to what is below it, and if one uses the Model-View-ViewModel pattern, it effectively becomes the only mechanism. This forces one to think very clearly about what the application can do, allows to change the UI without any side effects in the lower layers, and allows to test the application independent of the UI.


    http://wpfglue.wordpress.com
    • Marked as answer by Aland Li Tuesday, May 25, 2010 8:43 AM
    Monday, May 24, 2010 6:23 PM
  • The binding is much more flexible than winforms binding.

    One of the first little applications I wrote in WPF was a clock.  The hands are rectangles whose rotation is controlled by binding.

    You can bind things you wouldn't think of doing in winforms.

    I have a form which has two controls above one another.  The top one is a datagrid and the bottom one a treegrid.  I have the column widths of the treegrid bound to those of the datagrid.  As you resize the screen all the columns resize proportionately.  This is all done in xaml.

     

    • Marked as answer by Aland Li Tuesday, May 25, 2010 8:43 AM
    Monday, May 24, 2010 7:21 PM
  • Hi,

    @Aland : I was under impression that only one reply can be marked as answer, and so I unmarked your reply as answer. Sorry for that. Otherwise your answer was surely helpful.

    @Andy : Thanks for the example scenario.

    @hbarck : Your reply is really helpful to choose the architecture. Expertise of users is different thing; but while designing the system, one can surely decide what is better to choose.

    Thank you all.

    Niket

    Tuesday, May 25, 2010 10:47 AM
  • Hi Niketrk,

    Thanks for your reply and analysis of our replies. If you have some issues, please post here. You can unmark the reply if it does not help or does not meet your needs.

    Regards,
    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Tuesday, May 25, 2010 2:11 PM