http://updatecontrols.net/

Project Description

WPF and Silverlight data binding without INotifyPropertyChanged. It discovers dependencies automatically so you don't have to manage them in your View Model.

And it works with Winforms. Bind through code using events.

Support for Winforms, WPF, Silverlight 3, and Silverlight 4

This project compiles for all current .NET client platforms. This library is not compatible with Silverlight 2.

Example

Wrap your object before giving it to the WPF DataContext:
public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();
        DataContext = ForView.Wrap(new PersonViewModel(new Person()));
    }
}

The wrapped object given to DataContext is a plain-old-CLR-object.
public class PersonViewModel
{
    private Person _person;

    public PersonViewModel(Person person)
    {
        _person = person;
    }

    public Person Person
    {
        get { return _person; }
    }

    public string FirstLast
    {
        get { return _person.FirstName + " " + _person.LastName; }
    }

    public string LastFirst
    {
        get { return _person.LastName + ", " + _person.FirstName; }
    }

    public string Title
    {
        get { return "Person - " + (_person.DisplayStrategy == 0 ? FirstLast : LastFirst); }
    }
}

The underlying data object uses Independent properties to keep track of gets and sets. The wrapper can see these properties through layers of code, and automatically wires up property change notifications.
public class Person
{
    private string _firstName;
    private string _lastName;
    private int _displayStrategy;

    #region Independent properties
    // Generated by Update Controls --------------------------------
    private Independent _indDisplayStrategy = new Independent();
    private Independent _indFirstName = new Independent();
    private Independent _indLastName = new Independent();

    public string FirstName
    {
        get { _indFirstName.OnGet(); return _firstName; }
        set { _indFirstName.OnSet(); _firstName = value; }
    }

    public string LastName
    {
        get { _indLastName.OnGet(); return _lastName; }
        set { _indLastName.OnSet(); _lastName = value; }
    }

    public int DisplayStrategy
    {
        get { _indDisplayStrategy.OnGet(); return _displayStrategy; }
        set { _indDisplayStrategy.OnSet(); _displayStrategy = value; }
    }
    // End generated code --------------------------------
    #endregion
}
You can data bind to any property, even the ones that calculate their value based on independent properties. When the independent property is changed, the dependent ones are updated, too.

What just happened?
ForView.Wrap just created a wrapper object for you. This wrapper object has all of the properties of the object you passed in, but they are now bindable. The Silverlight version creates DependencyProperties for you. The WPF version implements INotifyPropertyChanged.

What's more, Update Controls is watching what your properties do. If they call OnGet(), or call anything that calls OnGet(), it sets up a dependency. Later, when something calls OnSet(), that DependencyProperty is updated with the new value.
Last edited Jul 16 at 2:50 PM by MichaelLPerry1971, version 10

 

Want to leave feedback?
Please use Discussions or Reviews instead.

Updating...
© 2006-2010 Microsoft | Get Help | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2010.8.10.17093