Pregunta

I have a simple Datagrid binded to an ObservableCollection from the ViewModel. This ObservableCollection is composed by a Custom Type, say ObservableCollection.

The ComplexType only have 2 properties, and only one is editable on the screen. The other one is a bool type that depends on the first.

When I edit the first property, it gets reflected to the ComplexType and it also change the second property. But the second property is not changed on the screen.

How can I update the second property on the screen?

¿Fue útil?

Solución

Try this:

public class ComplexType:INotifyPropertyChanged
{
    private object someProperty1;
    public object SomeProperty1
    {
        get{return someProperty1;}
        set
        {
            someProperty1=value;
            SomeProperty2=somefunc(someProperty1);

            If(PropertyChanged!=null){PropertyChanged(this, new PropertyChangedEventArgs(SomeProperty1));}
        }
    }

    private object someProperty2;
    public object SomeProperty2
    {
        get{return someProperty2;}
        set
        {    
        someProperty2=value;

        If(PropertyChanged!=null){PropertyChanged(this, new PropertyChangedEventArgs(SomeProperty2));}
        }

    public event PropertyChangedEventHandler PropertyChanged;
}

Otros consejos

An observable collection provides notification only when items are added, removed, or the whole collection is refreshed. You need to make sure that each property either raises the PropertyChanged event or is a dependency property if you want your UI to refresh when it changes.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top