Hi All,
I have a ViewModel base class that derives from DynamicObject. It wraps a single model class and supports bindings to the model's properties without needing to explicitly declare them.
In this class I override TryGetMemeber and TrySetMember to intercept binding calls and use reflection to get and set the underlying properties in the model.
I have unit tests set up on this that use impromptu to simulate bindings, and this all works fine. However when binding into a real view I run into a problem with type conversion, which doesn't occur with standard (not dynamic) View -> ViewModel bindings.
An example of the problem I am having is when a Textbox in a view that is bound to an Int32 typed property. With a standard viewmodel this works fine is is completely valid. With this dynamic setup, the Get binding works fine, but the set binding passes the value back to the View Model as a string and the SetValue operation fails as it is trying to push a string into an int property.
I have built my own type conversion class to handle this - and this does work - but as a standard binding handle this invisibly I am wondering if I can replace this class with something that already exists which will give a cleaner solution.
Really just wondering if anyone has done similar to this, or has any knowledge on how/where this type conversion takes place with bindings?
Cheers
Phil