enum in the model, how to us ethem in the viewmodel

Topics: Questions
Jul 25, 2014 at 12:29 PM
Edited Jul 25, 2014 at 1:03 PM
Hello,

in the model I used an enum like:
namespace CIP.Models.Base
{
public enum EmailTypeModel
{
    Prive,
    Zakelijk
}
}

I used this as a type in a class.


Do I have to make a viewmodel of it like this:

namespace CIP.ViewModels.Base
{
 using Catel;
using Catel.MVVM;
using Catel.Data;
using CIP.Models.Base;

class EmailTypeViewModel : ViewModelBase
{
    public EmailTypeViewModel(EmailTypeModel emailTypeModel)
    {
        Argument.IsNotNull(() => emailTypeModel);
        EmailTypeModel = emailTypeModel;
    }

    [Model]
    public EmailTypeModel EmailTypeModel
    {
        get { return GetValue<EmailTypeModel>(EmailTypeModelProperty); }
        set {  SetValue(EmailTypeModelProperty, value); }
    }

    public static readonly PropertyData EmailTypeModelProperty = RegisterProperty("EmailTypeModel",
        typeof (EmailTypeModel), null);
}
}

Or do you only register it in the viewmodel of the model it is used in?


I've been searching for this.
Because the viewmodel knows the model I can use the enum type. and in the XAML some converters.i

Thoughts and pointers are welcome.

Later I want to display the value son the screen ofcourse.

Kind regards

Jeroen
Coordinator
Jul 27, 2014 at 9:14 AM
An enum is not a model. An enum cannot be used as a model in Catel, only as a property on a view model to contain a state.

In your case you can remove the Model attribute from the property, the rest looks ok.
Marked as answer by JeroenE on 7/27/2014 at 11:53 PM