ApplyValidation doesn't work with nested propertys

Jan 20, 2011 at 10:10 PM
Edited Jan 21, 2011 at 12:51 AM

Hello,

 

thanks again for writing Caliburn, it really makes many things so much easier.

This however leads me to not supecting Caliburn at first when things don't work, like in this case.

My ViewModel exposes a rich Model (IdataErrorInfo, INPC) as Properties. Everything work fine except Validation Binding.

By digging into Caliburn I found that Caliburn checks if the ViewModel implements IDEI:

ConventionManager.ApplyValidation ===>
       if(typeof(IDataErrorInfo).IsAssignableFrom(viewModelType))
                binding.ValidatesOnDataErrors = true;
After implementing it in my VM so Caliburn could find it i found this part, which will call into ApplyValidation 1 step later:
ViewModelBinder.BindProperties ===>
convention.ApplyBinding(
                    viewModelType ,//parts.Length == 1 ? viewModelType : property.PropertyType,
                    cleanName.Replace('_''.'),
                    property,
                    element,
                    convention
                    );

Now, when Biding to a Model exposed as a Property on the VM, parts will be > 1 and Caliburn finally checks if the underlying DataType (string, int, double..) of
the Field I bound to implements IDEI, which is not the case.

I just commented the if-clause out. Will this cause any drawbacks, I guess there is a reason for it to be there ?

I also tried to get the actual type of the underlying model with Type.GetType(modelName), but that
doesn't work because it's in a different assembly.






Coordinator
Jan 21, 2011 at 3:07 AM
Edited Jan 21, 2011 at 3:08 AM

Would it be possible for you to create a small sample project that demonstrates the issue? That would really help me to investigate it thoroughly and see if I can provide a fix. Please email me as soon as you can at: robertheisenberg at hotmail dot com Thanks!

Jan 21, 2011 at 8:49 AM
Edited Jan 21, 2011 at 8:59 AM

Sure, will create a small sample over the weekend.

btw: The part commented out in the above post is the original code for the first Parameter for ApplyBinding. The actual parameter is the code i replaced it with. You should see the issue when looking at the code commented out.

When i have a control with Name="ExposedModelProperty_SomeProperty"

parts will be == 2 and viewModeltype will get replaced with the type of the property (int32, double, bool).

Then ApplyValidation will check if this type implements IDataErrorInfo, which will obviously fail and therefore it wont bind the Validation.

All other bindings work because they dont depend on the ViewModel type.

After replacing the code above, it will work if the VM implements IDataErrorInfo, even though it won't get used (at least in my case), it's just to trick caliburn to do the binding.

Coordinator
Jan 21, 2011 at 2:51 PM

Actually, before you create a sample, can you update to the latest code? It's different than what you show above, so I want to make sure that your issue hasn't already been fixed some time in the past.

Jan 21, 2011 at 11:13 PM

I looked at it and it seems that it's fixing the issue I had.

Going to load the newest code first the next time I run into something, lesson learned.

Thanks for the *really fast* fix and quick answers!