A former colleague of mine, Cecilia, just asked me how to access information about a XForm when using Page Type Builder. Normally when you use Page Type Builder you access the value of (EPiServer) properties with code properties such as this:
[PageTypeProperty] public virtual string MyProperty { get; set; } //Or.. [PageTypeProperty] public virtual string MyProperty { get { return this.GetPropertyValue(page => page.MyProperty); } }
But when it comes to a XForm you probably won’t be interested in the property’s value but instead in the property it self, or perhaps as in Cecilia’s case, in the property’s Form property from which you can get information about the form such as the form’s name. To make your code property return the actual property you can implement it like this:
[PageTypeProperty(Type = typeof(PropertyXForm)] public virtual PropertyXForm MyFormProperty { get { return (PropertyXForm) this.Property[this.GetPropertyName( page => page.XFormTeaser)]; } }
To instead make the code property return the actual XForm object you can implement it like this:
[PageTypeProperty(Type = typeof(PropertyXForm), Tab = typeof(Poll), SortOrder = 80, EditCaption = "Veckans fråga")] public virtual XForm MyFormProperty { get { return ((PropertyXForm) this.Property[this.GetPropertyName( page => page.XFormTeaser)]).Form; } }
PS. For updates about new posts, sites I find useful and the occasional rant you can follow me on Twitter. You are also most welcome to subscribe to the RSS-feed.
Similar articles
- Developing with Page Type Builder – Advanced Property Access
- Developing with Page Type Builder – Inheritance and Specifying Property Types
- Define tabs in code with Page Type Builder 0.8.5
- Page Type Builder 2 Preview 1 released!
- Working with Dynamic Properties and Page Type Builder
- Developing with Page Type Builder – Using Interfaces and Advanced Inheritance
- How to create a custom EPiServer property
- Page Type Builder 0.8 released – Finally!
My book
Want a structured way to learn EPiServer 7 development? Check out my book on Leanpub!
Comments
comments powered by Disqus