There are 2 ways to get the automatic notice target object if the source object changed (for example: the value) when you using WPF data binding: the one is Dependency Properties, the other one is INotifyPropertyChanged:

InotifyPropertyChanged  sample:

public class IODataPresentation : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    private string _ValueString;

    public string ValueString
    {
        get { return _ValueString; }
        set
        {
            _ValueString = value;

            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("ValueString"));
            }

        }
    }
    public IODataPresentation() { }
}

DependencyProperties sample:

// Dependency Property
public static readonly DependencyProperty NewValueStringProperty =
    DependencyProperty.Register("ValueString", typeof(string),
    typeof(UDirectIOBlock), new FrameworkPropertyMetadata(""));

public string NewValueString
{
    get { return (string)GetValue(NewValueStringProperty); }
    set { SetValue(NewValueStringProperty, value); }
}

About their differences, please read 2 great articles here and here.

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2013 CodeEase.com Suffusion theme by Sayontan Sinha