The property is read-only on model, but the mode is not OneWay

Jun 2, 2012 at 3:38 PM
Edited Jun 2, 2012 at 3:42 PM

I have a model with some calculated properties. Therefore I have defined them on the model with a private setter:

public int Year
{
    get
    {
        return GetValue<int>(YearProperty);
    }
    private set
    {
        SetValue(YearProperty, value);
    }
}
The properties are exposed on the viewmodel using the ExposeAttribute
 
[Model]
[Expose("Year")]
public Infrastructure.TimeLog TimeLog
{
    get
    {
        return GetValue<Infrastructure.TimeLog>(TimeLogProperty);
    }
    private set
    {
        SetValue(TimeLogProperty, value);
    }
}

In my View I bind the property OneWay:
 
<TextBlock Grid.Column="1" Text="{Binding Year, Mode=OneWay}" />

 


However, when I try to instantiate the ViewModel I get the error

The property 'Year' is read-only on model 'TimeLog', but the mode is not OneWay.

I have however set the Binding in XAML to OneWay. Is this not supported in Catel?

Please, where is the error of my way? :)

P.S. Sorry for the layout, the Code Snippets seem somewhat over enthousiastic :D

Jun 2, 2012 at 3:56 PM
Edited Jun 2, 2012 at 3:56 PM

Try setting the mode on the expose attribute. ie.

[Expose("Year", Mode=ViewModelToModelMode.OneWay]

See if that helps.

Jun 2, 2012 at 4:03 PM

Thanks, that did the trick :)