Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,784 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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?
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.