Binding PropertyStatus to an indexer

Binding PropertyStatus to an indexer

Old forum URL: forums.lhotka.net/forums/t/9350.aspx


smumcounty posted on Tuesday, August 10, 2010

I am using CSLA with Silverlight and trying to bind a PropertyStatus control to a property using an indexer:

 

<

 

 

csla:PropertyStatus Property="{Binding Path=Model.Custom[CustomText].Value}"/>

I'm getting an "Object instance not set to an instance of an object" error when I do this. It looks like the PropertyStatus.GetRealSource method can't make sense of the indexer syntax.

Is there a binding syntax I can use to get this to work or will the PropertyStatus control simply not work with an indexer?

RockfordLhotka replied on Tuesday, August 10, 2010

Quite a few things don't work with indexers - PropertyStatus being just one of them. I don't think any managed backing fields, or PropertyInfo<T> or any of that infrastructure would work either.

Indexers are a way of creating a collection-like interface. If you need such an interface, you should put the elements into a BusinessListBase so they can be managed as a collection. Or if you don't need all the BLB functionality, you can use MobileList<T>.

smumcounty replied on Tuesday, August 10, 2010

My application, allows clients to create their own custom properties associated with a business entity. I was attempting to create a child Custom class that would hold the custom properties. Each of the custom properties would be accessed through the indexer of the Custom class using the name of the property. Each CustomProperty class contains a Value and a Label property. I have no problem binding prompts to Custom[CustomPropertyName].Value and Custom[CustomPropertyName].Label.  So that works well. The Value property is a managed field which can have broken rules so my hope was to bind the PropertyStatus control to Custom[CustomPropertyName].Value. But as you note the PropertyStatus control is not designed to handle the indexer syntax.

How could I use the BusinessListBase in this scenario to allow me to bind to the PropertyStatus control?

smumcounty replied on Tuesday, August 10, 2010

A little more information:

The Custom class has a CustomProperties property which is derived from BusinessListBase and whose members are of type CustomProperty which is derived from BusinessBase. The indexer on the Custom class essentially returns the CustomProperty from CustomProperties with the indicated name.

RockfordLhotka replied on Tuesday, August 10, 2010

I am not against PropertyStatus supporting an indexer. But you must realize that in CSLA 4 the PropertyStatus control only works with registered properties (it relies on getting a PropertyInfo<T>), so I suspect the issue is deeper than just the control.

.NET defines a model for what you are trying to do - a dynamic type descriptor. I don't think that concept translated to Silverlight - and maybe it never will now that the DLR exists. I'm bringing these technologies into the conversation, because you should try and infer (as much as possible) where Microsoft is likely to go with dynamic types over time, so your code can enjoy the benefits of their work.

I rather suspect that they'll adopt the DLR dynamic object approach - I know ASP.NET MVC 3 uses it for example. If that ends up being the way .NET/SL move, that'll be the way CSLA will move too.

In other words, I may end up devising a scheme by which a dynamic type with dynamic properties can have dynamic registration of those properties. Hopefully that's not too hard - but it isn't something I've explored.

Again, I'm rambling on about this to provide you with food for thought. None of this is high on my list right now, as my focus is on three things:

  1. CSLA 4 ebooks
  2. CSLA 4 videos
  3. CSLA 4 for Windows Phone

If you want to explore some ideas around dynamic types and registering properties and enhancing PropertyStatus to support them, I'd welcome your input.

MAN-U replied on Friday, August 13, 2010

Can you provide a code snippet or more clarity on ‘devising a scheme by which a dynamic type with dynamic properties can have dynamic registration of those properties’ 

 

We have a registered property in our Business Class of type PropertyCollection, which holds the custom fields defined by our customer.  Customers can define the name, data type and validation rules of the custom fields.  I’m looking for a way to validate the custom fields using property status.  

RockfordLhotka replied on Friday, August 13, 2010

I used the phrase "devising a scheme" because this isn't something I've thought through. Since I haven't thought it through, I surely can't provide a code snippet Big Smile

Copyright (c) Marimer LLC