I'm somewhat new with CSLA so this could be a silly question, but is there a way to get all the broken rules for a specific Property.
IE: Person.LastName = "123456"
I would like to have the broken rule "Last Name Invalid - Only numbers not allowed"
I would like to have something like
Person.LastName.BrokenRules containing only errors related to the Last Name
even if there are plenty of other broken rules.
let me know
Thanks,
jean
BusinessObjects expose a GetBrokenRules method that returns a collection with all broken rules for this instance.
You can do a linq query to get all broken rules for a given property.
Right, but here is what i'm trying to do, in the XAML I need to change the TextBox border color if there is an error , but it seems that the BrokenRuleCollection does not trigger an event or somehow the xaml does not get it.
So for each properties of the object I need to know if there are broken rules related to it, in the XAML so I can first change the background of the textbox and second display the error in another textblock for that same properties.
Can you bind the textbox's border to the property's propertystatus' IsValid property and just throw a converter on it ... i.e. PropertyValidToControlBackgroundConverter or what have you.
This is the purpose behind the Csla.Xaml.PropertyInfo control. It elevates all the metastate about a property so everything is bindable to other XAML controls.
I discuss this in the Using CSLA 4 ebook, and many of the sample apps use this technique.
What is even nicer, is that you can use PropertyInfo within a control template so you can create reusable styles that consistently display errors or other metastate values (tooltips, etc) based on the metadata in the business objects.
I see , now I tried this code in my Win8 application XAML
<csla:PropertyInfo x:Name="LastNamePropertyInfo" Source="{Binding PersonEdit.LastName}" >
<TextBlock Text="{Binding ElementName=LastNamePropertyInfo, Path=IsValid}"
And the TextBlock always return true even I have intentionally make the validation for that field fail.
Anything I'm doing wrong ?
By "Win8" do you mean WinRT?
Some features of the WinRT runtime are more similar to Silverlight 2 than to modern XAML. As a result the PropertyInfo control uses the SL2 binding scheme because the modern binding scheme can't be implemented :(
<csla:PropertyInfo Name="blah" Source="{Binding PersonEdit}" PropertyName="LastName"/>
The Source property must reference the source business object.
The PropertyName property is a string that indicates the property to which we're "binding".
Yeah I mean WinRT/Metro/Windows Store app/Modern app / what ever they are going to call it in the future :-)
And the SL2 binding scheme works, thanks
<TextBlock Style="{StaticResource ViewerFormTitleStyle}" HorizontalAlignment="left" Text="Last Name" Foreground="{Binding AccentColorBrush, Converter={StaticResource ColorConverter}}" />
<controls:FormFieldTextBox Style="{StaticResource FormFieldStyle}" Text="{Binding PersonEdit.LastName, Mode=TwoWay}"
behaviors:HighlightFormFieldOnErrors.PropertyErrors="{Binding ElementName=LastNamePropertyInfo, Path=IsValid}" />
<TextBlock Style="{StaticResource ErrorMessageStyle}" Text="{Binding ElementName=LastNamePropertyInfo, Path=BrokenRules, Mode=OneWay, Converter={StaticResource FirstErrorConverter}}" TextWrapping="Wrap"/>
<csla:PropertyInfo x:Name="LastNamePropertyInfo" Source="{Binding PersonEdit}" Property="LastName" />
It is strange that in that code, the Behavior works (ElementName=LastNamePropertyInfo Path= IsValid )
and the
Converter does not with Text="{Binding ElementName=LastNamePropertyInfo, Path=BrokenRules,
It seems like i'm not getting an event for BrokenRules but I'm with IsValid
Copyright (c) Marimer LLC