XAML Binding to complex value objects

Posted by Gus on Stack Overflow See other posts from Stack Overflow or by Gus
Published on 2010-06-07T14:26:13Z Indexed on 2010/06/08 2:22 UTC
Read the original article Hit count: 374

I have a complex value object class that has 1) a number or read-only properties; 2) a private constructor; and 3) a number of static singleton instance properties [so the properties of a ComplexValueObject never change and an individual value is instantiated once in the application's lifecycle].

public class ComplexValueClass
{
    /* A number of read only properties */
    private readonly string _propertyOne;
    public string PropertyOne
    {
        get
        {
            return _propertyOne;
        }
    }

    private readonly string _propertyTwo;
    public string PropertyTwo
    {
        get
        {
            return _propertyTwo;
        }
    }

    /* a private constructor */
    private ComplexValueClass(string propertyOne, string propertyTwo)
    {
        _propertyOne = propertyOne;
        _propertyTwo = PropertyTwo;
    }

    /* a number of singleton instances */
    private static ComplexValueClass _complexValueObjectOne;
    public static ComplexValueClass ComplexValueObjectOne
    {
        get
        {
            if (_complexValueObjectOne == null)
            {
                _complexValueObjectOne = new ComplexValueClass("string one", "string two");
            }
            return _complexValueObjectOne;
        }
    }

    private static ComplexValueClass _complexValueObjectTwo;
    public static ComplexValueClass ComplexValueObjectTwo
    {
        get
        {
            if (_complexValueObjectTwo == null)
            {
                _complexValueObjectTwo = new ComplexValueClass("string three", "string four");
            }
            return _complexValueObjectTwo;
        }
    }
}

I have a data context class that looks something like this:

public class DataContextClass : INotifyPropertyChanged
{


    private ComplexValueClass _complexValueClass;
    public ComplexValueClass ComplexValueObject
    {
        get
        {
            return _complexValueClass;
        }
        set
        {
            _complexValueClass = value;
            PropertyChanged(this, new PropertyChangedEventArgs("ComplexValueObject"));
        } 
    }
}  

I would like to write a XAML binding statement to a property on my complex value object that updates the UI whenever the entire complex value object changes. What is the best and/or most concise way of doing this? I have something like:

<Object Value="{Binding ComplexValueObject.PropertyOne}" />

but the UI does not update when ComplexValueObject as a whole changes.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf