ApplyValidation doesn't work with nested propertys

Jan 20, 2011 at 9:10 PM
Edited Jan 20, 2011 at 11:51 PM



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 ===>
                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 ===>
                    viewModelType ,//parts.Length == 1 ? viewModelType : property.PropertyType,

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.

Jan 21, 2011 at 2:07 AM
Edited Jan 21, 2011 at 2: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 7:49 AM
Edited Jan 21, 2011 at 7: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.

Jan 21, 2011 at 1: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 10: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!