Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark Bowser 263 posts 849 karma points c-trib
    Aug 13, 2018 @ 21:43
    Mark Bowser
    0

    nuPickers with ModelsBuilder

    We have an Umbraco 7.11.1 site with nuPickers 1.7.0.

    My goal is to get nuPickers to cooperate with ModelsBuilder really nicely. Right now, all of the nuPicker properties on my ModelsBuilder models are of type nuPickers.Picker. I want them to have the type of the enum that my nuPicker is using as a data source. I have a nuPickers: Enum RadioButton Picker and want the ModelsBuilder model to have a property like this:

        ///<summary>
        /// Left/Right Orientation
        ///</summary>
        [ImplementPropertyType("leftRightOrientation")]
        public nuPickers.Picker LeftRightOrientation
        {
            get { return this.GetPropertyValue<nuPickers.Picker>("leftRightOrientation"); }
        }
    

    Unfortunately, there isn't a way to easily get the enum value I want from that nuPickers.Picker. What would be yamazing is if there was a way for me to get ModelsBuilder to generate the property like this. I'm guessing changes would need to be made to the PropertyValueConverter of nuPickers?

        ///<summary>
        /// Left/Right Orientation
        ///</summary>
        [ImplementPropertyType("leftRightOrientation")]
        public Models.DatatypePrevalues.LeftRightOrientation LeftRightOrientation
        {
            get { return this.GetPropertyValue<Models.DatatypePrevalues.LeftRightOrientation>("leftRightOrientation"); }
        }
    

    Any ideas about how that could be accomplished?

  • Dave Woestenborghs 3213 posts 10799 karma points MVP 4x admin c-trib
    Aug 14, 2018 @ 07:31
    Dave Woestenborghs
    102

    Hi Mark,

    You don't need to create a custom property value converter. You can change the model generation. (https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/Control-Generation)

    What you need to do is create a partial class with the same name as the generated model in the same folder where the models are generated by Models builder.

    In this class you can than define a property like this :

    [ImplementPropertyType("leftRightOrientation")]
        public Models.DatatypePrevalues.LeftRightOrientation LeftRightOrientation
        {
            get { 
    var enumValue = this.GetPropertyValue<nuPickers.Picker>("leftRightOrientation");
                    return enumValue.AsEnums<Models.DatatypePrevalues.LeftRightOrientation>();
    }
        }
    

    After that generate your models again. ModelsBuilder will now not generate this property anymore, but will use your own implemantation for this nuPicker based property.

    Dave

  • Mark Bowser 263 posts 849 karma points c-trib
    Aug 15, 2018 @ 19:18
    Mark Bowser
    0

    Worked great! Thanks

Please Sign in or register to post replies

Write your reply to:

Draft