Quantcast
Channel: patterns & practices: Prism
Viewing all articles
Browse latest Browse all 1878

New Post: UI Validation for multiple views in a region does not work

$
0
0
Hi Gabriel,

I have 2 View classes V1.xaml and V2.xaml both have a corresponding datacontext set as V1VM.cs and V2VM.cs. There is a presentation object Root.cs having two properties Root.Property1 and Root.Property2 where Property1 returns Child1.cs and Property2 returns Child2.cs, both are complex types. Now, in the view models, Child1.cs and Child2.cs are exposed as properties. On Application load, V1, V2, V1VM and V2VM are all loaded to the Mef container. V1 and V2 are registered to the main Content region through AutoPopulateExportedViewBehavior. Onn INavigationAware.OnNavigateFrom(), the view model properties are set from the Root object. In the XAML, the textbox property is set as below;

<TextBox name="txtNoOfStages" Text="{Binding Child1.NoOfStages, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{StaticResource TextBoxErrorTemplate}" Style="{DynamicResource TextBoxMedium}" />

I am using the MVVMValidator to do the validation. So I implement the IDataErrorInfo and configure the validation rules on the Child1.cs and Child2.cs. On a global save command, my FormValidator component which adds the instance of V1VM and V2VM fires the Validate method on the Child1 and Child2 instance accessible through the view models. Here the validation happens on the presentation objects and the error is only displayed on the current active View on the region. If I now activate the second view model on the same content region, I do not get to see the adorners though the rules get executed.

Let me know if you still need a sample and I can share one.

Regards,
Jeevan

Viewing all articles
Browse latest Browse all 1878

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>