WPF ComboBox not showing validation rule that a TextBox does.

WPF ComboBox not showing validation rule that a TextBox does.

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


tdrake posted on Thursday, August 28, 2008

Hi WPF'ers....

After some searching I can't see anyone else with this problem:

Business rule for Customer is such:
ValidationRules.AddRule(Csla.Validation.CommonRules.StringRequired, CustomerProperty);
        ValidationRules.AddRule(
          Csla.Validation.CommonRules.StringMaxLength,
          new Csla.Validation.CommonRules.MaxLengthRuleArgs(CustomerProperty, 15));
and a TextBox defined as such:
<TextBox Margin="5 0 5 0" Text="{Binding Customer, Converter={StaticResource IdentityConverter},
                    ValidatesOnDataErrors=True}"></TextBox>

Works brilliantly...

Replace text box with a matching pair lookup as such:
<ComboBox Margin="5 0 5 0"
                  ItemsSource="{Binding Source={StaticResource ListCustomers}}"
                  DisplayMemberPath="Value"
                  SelectedValuePath="Key"
                  SelectedValue="{Binding Path=Customer}" />

Now when I enter form for a new customer, I get no error - I like Rocky's little red dot.

Looked through the using CSLA 3.0 and probably say that the whole "rules bit" of CSLA is my current weak point (I'm sure there are more areas I don't know I don't know), so sorry if I've missed something.

Anyway, software going to use tomorrow with or without the error flag, but I'd like be know how to do it for the next release!!

Anyway, while I've tinkered with CSLA for about 3 years, and built a demo or two (Winform), this is my first real user app - WPF,WCF and Linq - do I feel like I'm cutting edge or what??!!??

Cheers Tony Drake
Melb Aus.

Curelom replied on Thursday, August 28, 2008

You probably are getting an error, but your combobox style is not showing it.  Try something like below.  You will need to supply your own brushes.

<Style x:Key="{x:Type ComboBox}" TargetType="{x:Type ComboBox}">

<Setter Property="Validation.ErrorTemplate" Value="{StaticResource validationTemplate}" />

<Style.Triggers>

<Trigger Property="Validation.HasError" Value="True">

<Setter Property="BorderBrush" Value="{DynamicResource BorderErrorBrush}"/>

<Setter Property="Opacity" Value="0.84"/>

<Setter Property="Background" Value="{DynamicResource BackgroundErrorBrush}"/>

</Trigger>

<Trigger Property="IsReadOnly" Value="True">

<Setter Property="IsEnabled" Value="False" />

</Trigger>

</Style.Triggers>

</Style>

tdrake replied on Thursday, August 28, 2008

thanks - I am getting the error (as the business object is not valid) until I enter data  - the user doesn't get any feedback apart from that - so I think you've hit the nail - thanks for the quick reply.

I'll workup the xml (and built a SP1 with new validate feedback) and report back.

Cheers Tony

Copyright (c) Marimer LLC