Broken Rule for 1 property

Broken Rule for 1 property

Old forum URL: forums.lhotka.net/forums/t/11862.aspx


jteneglio posted on Friday, March 01, 2013

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

JonnyBee replied on Saturday, March 02, 2013

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. 

jteneglio replied on Tuesday, March 05, 2013

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.

skagen00 replied on Tuesday, March 05, 2013

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.

 

RockfordLhotka replied on Tuesday, March 05, 2013

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.

jteneglio replied on Wednesday, March 06, 2013

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 ?

RockfordLhotka replied on Wednesday, March 06, 2013

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".

jteneglio replied on Thursday, March 07, 2013

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

jteneglio replied on Sunday, March 10, 2013

<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