Click here to Skip to main content
15,892,059 members
Articles / Web Development

WPF Two-way Databinding in ASP.NET - Enabling MVVM

Rate me:
Please Sign up or sign in to vote.
4.88/5 (35 votes)
29 Jan 2011CPOL21 min read 139.8K   66  
Bringing WPF like declarative data binding to ASP.NET Web Forms to enable declarative two-way data binding to any object whilst opening up MVVM UI development.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using Binding.ControlWrappers;
using Binding.Services;
using System.ComponentModel;

namespace Binding.Interfaces
{
    

    /// <summary>
    /// Strongly typed IBindingContainer
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IBindingContainer<T> : IBindingContainer
    {
        T TypedDataContext { get;}
    }

    /// <summary>
    /// Implement this interface on your control container (page, form, window etc) in order facilitate databinding
    /// </summary>
    public interface IBindingContainer: IBindingTarget
    {
        //If implementing this interface on the a System.Web.UI.Page you
        //are only required to implement this one property explictly
        /// <summary>
        /// The ViewModel used to supply data to and receive values from the view
        /// </summary>
        /// <remarks>If you want cascading updates to work then this object must implement INotifyPropertyChanged</remarks>
        //object BindingContext { get; set; }

        //All implemented by System.Web.UI.Page
        void DataBind();
        bool IsPostBack { get; }
        event EventHandler Load;

        object DataContext { get; set; }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions