question

Flithor-2893 avatar image
0 Votes"
Flithor-2893 asked ·

How to merge single binding validationrule errors to bindinggroup?

Example:

 <Grid>
     <Grid.BindingGroup>
         <BindingGroup x:Name="Group"/>
     </Grid.BindingGroup>
     <TextBox>
         <TextBox.Text>
             <Binding Path="Name" BindingGroupName="Group">
                 <Binding.ValidationRules>
                     <rules:MyCustomCommonRule/>
                 </Binding.ValidationRules>
             </Binding>
         </TextBox.Text>
     </TextBox>
     <TextBox Text="{Binding Name2}"/>
     <Button Content="Commit"
               IsEnabled="{Binding ElementName=Group,
               Path=HasValidationError,
               Converter={StaticResource NotConverter}}"/>
 </Grid>

If MyCustomCommonRule has return validation error, how to make the button disabled?











windows-wpf
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AlexLi-MSFT avatar image
1 Vote"
AlexLi-MSFT answered ·

Hi,

Welcome to our Microsoft Q&A platform!

Grid doesn't have HasValidationError property.

If you want to use code behind ,see my code:

 if (Validation.GetHasError(GridName) == true)
 {
 ButtonName.IsEnabled = false;
 }

or you can use xaml:

 <Button   >
             <Button.Style>
                 <Style TargetType="Button">
                     <Style.Triggers>
                         <DataTrigger Binding="{Binding ElementName=Grid1,Path=(Validation.HasError),UpdateSourceTrigger=PropertyChanged}" Value="True">
                             <Setter Property="IsEnabled" Value="False"/>
                         </DataTrigger>
                     </Style.Triggers>
                 </Style>
             </Button.Style>


Thanks.


· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.