Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey there,
long time since i asked a question. I want to display all validation-errors and disable two buttons addicted from the validation-error.

Background:
I have a table where the user can add and delete rows. The primerykey (Number)
shall be validated and if there is an error the add or remove button have to be disabled.
1: Error -> Key-Exsists -> Disable add button; enable remove button
2: Error -> Key is used in other table -> disable remove button

So it's possible that both errors appear at the same time. Therefor i need some help.
I use the ValidationList of Rohit Dot net: WPF - Multiple Validation on Single Control[^]

My error-template looks like:
HTML
 <ControlTemplate 
                x:Key="validationErrorTemplate">
                <DockPanel>
                    <StackPanel 
                        Orientation="Horizontal" 
                        DockPanel.Dock="Top">
                        <Grid 
                            Width="12" 
                            Height="12">
                            <Ellipse 
                                Width="12" 
                                Height="12"
                                Fill="Red" 
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"/>
                            <TextBlock 
                                Foreground="White"
                                FontWeight="Heavy"
                                FontSize="8" 
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center" 
                                TextAlignment="Center"
                                ToolTip="{Binding Path=ErrorContent}" />
                        </Grid>
                        <TextBlock 
                            Text="{Binding                                        
                                    Path=ErrorContent,
                                    UpdateSourceTrigger=PropertyChanged,
                                    ValidatesOnDataErrors=True,
                                    ValidatesOnExceptions=True}"  
                   FontSize="12"  
                   Foreground="Red"  
                   Margin="5 0 0 0"/>
                    </StackPanel>
                    <AdornedElementPlaceholder
                        x:Name="ErrorAdorner" />
                </DockPanel>
</ControlTemplate>


I want something like a converter which has the validationerrors as input and return them gathered as string. Additional i need some mechanism to disable the both buttons. Momentary i use Button-Styles for that:
HTML
<Style 
                x:Key="PopUpAddButtonStyle"
                BasedOn="{StaticResource {x:Type Button}}"
                TargetType="{x:Type Button}">
                <Setter Property="IsEnabled" Value="False" />
                <Style.Triggers>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding ElementName=TextBoxA, Path=(Validation.HasError)}" Value="false"/>
                            <Condition Binding="{Binding ElementName=TextBoxB, Path=(Validation.HasError)}" Value="false" />
                            <Condition Binding="{Binding ElementName=TextBoxC, Path=(Validation.HasError)}" Value="false" />
                            <Condition Binding="{Binding ElementName=TextBoxD, Path=(Validation.HasError)}" Value="false" />
                            <Condition Binding="{Binding ElementName=TextBoxE, Path=(Validation.HasError)}" Value="false" />
                        </MultiDataTrigger.Conditions>
                        <Setter Property="IsEnabled" Value="True" />
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>

Thanks for any help.
Greetings 3DC#
Posted
Comments
ZurdoDev 30-Jun-15 8:14am    
Use the validation summary control.
3DC# 1-Jul-15 8:52am    
Thank you for that tip. I tried to implement different examples but it doesn't work.
I guess the main problem is, that the textbox-text-validation stops when an error occurs. How can i disable that behavior or how can i force to validate each defined rule?

Thanks for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900