SimpleApp PropertyStatus binding syntax

SimpleApp PropertyStatus binding syntax

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


nhwilly posted on Monday, July 19, 2010

It seems the SimpleApp that comes with the v4.0 Samples has syntax that isn't right.  Specifically, it doesn't like "TargetControl".  I've seen discussions about deprecating that.

For those of us that learn best through samples, can someone tell me what the latest is for the sample code below?

<StackPanel Orientation="Horizontal" Margin="5,5,5,5">
      <TextBlock Width="100" Foreground="White" Text="Name" />
      <TextBox x:Name="NameTextBox" Width="150" Text="{Binding Name, Mode=TwoWay}" />
      <csla:PropertyStatus TargetControl="{Binding ElementName=NameTextBox}" Property="{Binding Name}" Margin="5,0,0,0" Style="{StaticResource PropertyStatusStyle1}" Foreground="#FF69ED12" />
</StackPanel>

Thanks.

 

RockfordLhotka replied on Monday, July 19, 2010

TargetControl is gone in CSLA 4.

The replacement technique is to have the UI control bind to the PropertyStatus control. So give the PropertyStatus control a name, and then bind the IsEnabled property (or whatever you want) on the TextBox to a property on PropertyStatus.

PropertyStatus exposes several properties that provide information about the property's status, enabling you to control some or all of your UI as you desire.

marthac replied on Wednesday, August 25, 2010

Is there any way you can give me a simple code snippet that shows how to do this.
I'm new to xaml as well as CSLA.
I'm specifically trying to figure our how to hide a ctrl when CanReadProperty returns false
Any help would be greatly appreciated. Big Smile

RockfordLhotka replied on Wednesday, August 25, 2010

SimpleApp has a VisibilityConverter in the codebase, and it is used (through data binding) to turn on/off the Canvas overlay. You can use the same binding syntax to make other controls visible/hidden.

Jav replied on Wednesday, August 25, 2010

Somehow the PropertyStatus control in my code is not behaving as flawlessly as it did in 3.8.4

Here is the code from SimpleApp which appears to work most of the time:
            <TextBox x:Name="NameTextBox" Width="150"
 Text="{Binding Mode=TwoWay, Path=Name, ValidatesOnNotifyDataErrors=False}" />
            <csla:PropertyStatus Property="{Binding Name}" Margin="5,0,0,0" Foreground="#FF69ED12" />

Here is the code from one of my pages - Mine is an AutocompleteBox, not a TextBox. The field is Required. The control only shows up if I type a character and then remove it with a backspace:
          Text="{Binding Path=Character, Mode=TwoWay, ValidatesOnNotifyDataErrors=False}"
         <Csla:PropertyStatus Property="{Binding Character}" Margin="5,0,0,0"  Foreground="#FF69ED12"/>  

On the same page, I have a set of CheckBoxes, one of which must be checked or a rule is broken.  It was working just fine in 3.8.4, but in 4.0.1, the PropertyStatus does not even show up.  I know that the object is invalid because there is a checkbox bound to IsValid which is behaving as expected. Here the PropertyStatus control never lights up no matter what I do.

Jav

RockfordLhotka replied on Wednesday, August 25, 2010

And you are running 4.0.1? There's a bug in PropertyStatus dealing with the control disappearing, and that is fixed in 4.0.1.

marthac replied on Wednesday, August 25, 2010

OK I got it to work by setting the visibility of the StackPanel using the VisibilityConverter (from SimpleApp).
Here is the code snippet for anyone who needs to do a similar thing.

                    <StackPanel Orientation="Horizontal" Margin="5,5,5,5"
                                Visibility="{Binding ElementName=SSNPropertyStatus, Path=CanRead, Converter={StaticResource VisibilityConverter}}">
                        <TextBlock Width="100" Foreground="Blue" Text="Birth Date Status: " TextAlignment="Right" />
                        <TextBox x:Name="SSNStatusTextBox" Width="150" Text="{Binding SsnStatusMoniker, Mode=TwoWay}" />
                        <csla:PropertyStatus x:Name="SSNPropertyStatus" Property="{Binding SsnStatusMoniker}"/>
                    </StackPanel>

Jav replied on Wednesday, August 25, 2010

Yes I am running 4.0.1
It is strange - it makes no sense.  So far I have two pages on which I have installed the PropertyStatus Control.  On both pages it is added to AutocompleBoxes.  In both I use StringRequired DataAnnotation.  In one, it works like clockwork.  In the other it doesn't.  It only appears (almost reluctantly :)) after I type something and then remove the text. The AutoCompleteBoxes are monotonously similar - both have ItemSource set to different MobileList< BusinessBase >.

The checkboxes (there are 18 of them) I mentioned earlier - I have changed the implementation. In the Property Set of each chechbox, I call a method which ORs all checkbox fields to set a single property which has a DataAnnotation requiring that the value must be 1.  It is working just fine, but the PropertyStatus bound to that single property does not even show up.

If there is some test I can perform to help solve this riddle, I'll be happy to do it.

Jav

Jav replied on Wednesday, August 25, 2010

Jav
PropertyStatus bound to that single property does not even show up

 

Sorry - a correction.  The above statement about the CheckBox connected Propertystatus is not correct.  The PropertyStatus does not show up originally. But if I check one checkbox and then uncheck it, the PropertyStaus does show up.  In other words, the behavior in both, the AutocompleteBox and the checkbox group is the same. Beside this PropertyStatus Control I placed a checkbox attached to the same exact property as the PS control.  That checkbox shows the red margin indicating SL error diplay correctly.

Also I am not implying that AutCompleteness of textbox has anything to do with it.  I just haven't tested it with an ordinary TextBox yet.

Copyright (c) Marimer LLC