Trouble desabling a button when using Validation rules
-
Monday, August 27, 2012 12:33 PM
Dear all,
I have the following control template triger in a style I have for my buttons:
<ControlTemplate.Triggers> <Trigger Property="IsPressed" Value="True"> <Trigger.EnterActions> <BeginStoryboard Storyboard="{StaticResource Press}" /> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard Storyboard="{StaticResource Release}" /> </Trigger.ExitActions> <Setter Property="Foreground" Value="{DynamicResource {x:Static s:SurfaceColors.ButtonForegroundPressedBrushKey}}"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Fill" Value="{DynamicResource {x:Static s:SurfaceColors.ButtonBackgroundDisabledBrushKey}}" TargetName="ButtonBody" /> <Setter Property="Foreground" Value="{DynamicResource {x:Static s:SurfaceColors.ButtonForegroundDisabledBrushKey}}"/> <Setter Property="Opacity" Value="0.33" TargetName="Content" /> </Trigger> <!--<Trigger Property="IsEnabled" Value="false" />--> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding ElementName=_Nom, Path=(Validation.HasError)}" Value="false" /> <Condition Binding="{Binding ElementName=_Prenom, Path=(Validation.HasError)}" Value="false" /> <Condition Binding="{Binding ElementName=_company, Path=(Validation.HasError)}" Value="false" /> <Condition Binding="{Binding ElementName=_role, Path=(Validation.HasError)}" Value="false" /> <Condition Binding="{Binding ElementName=_adresse1, Path=(Validation.HasError)}" Value="false" /> <Condition Binding="{Binding ElementName=_City, Path=(Validation.HasError)}" Value="false" /> <Condition Binding="{Binding ElementName=_Zip, Path=(Validation.HasError)}" Value="false" /> <Condition Binding="{Binding ElementName=_mail, Path=(Validation.HasError)}" Value="false" /> <Condition Binding="{Binding ElementName=_tel, Path=(Validation.HasError)}" Value="false" /> </MultiDataTrigger.Conditions> <Setter Property="IsEnabled" Value="true" /> </MultiDataTrigger> </ControlTemplate.Triggers>Then for each of my form field I have setup validation rules as follow :
<TextBox x:Name="_mail" Style="{StaticResource DefaultTextBox}" Grid.Column="1" Grid.Row="5" Margin="10,5,10,5" BorderBrush="LightBlue" BorderThickness="2" Validation.ErrorTemplate="{StaticResource validationTemplate}"> <TextBox.Text> <Binding Path="CurrentLead.Email" UpdateSourceTrigger="LostFocus" > <Binding.ValidationRules> <validators:IsEmptyStringValidationRules ValidatesOnTargetUpdated="True"/> <validators:IsEmailValidationRules ValidatesOnTargetUpdated="True"/> <ExceptionValidationRule /> </Binding.ValidationRules> </Binding> <TextBox.Text> <TextBox>Whatever the status of my validation the Button isEnable prperty is not affected.
Do you see anything wrong in what I have done which culd prevent ?
regards
serge
Your knowledge is enhanced by that of others.
All Replies
-
Tuesday, August 28, 2012 7:24 AMModerator
Hi Serge,
I suggest you use DataTrigger, instead of MultiDataTrigger, refer to below code snippet:
<ControlTemplate x:Key="buttonTemplate" TargetType="{x:Type Button}"> <Grid> <Ellipse Name="ButtonBody" Fill="Orange" Width="100" Height="100"> </Ellipse> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Fill" Value="Red" TargetName="ButtonBody" /> </Trigger> <DataTrigger Binding="{Binding ElementName=_Nom,Path=(Validation.HasError)}" Value="True"> <Setter Property="IsEnabled" Value="False" /> </DataTrigger> <DataTrigger Binding="{Binding ElementName=_Mail,Path=(Validation.HasError)}" Value="True"> <Setter Property="IsEnabled" Value="False" /> </DataTrigger> </ControlTemplate.Triggers> </ControlTemplate>Best regards,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked As Answer by Serge Calderara Thursday, August 30, 2012 5:06 PM
-
Thursday, August 30, 2012 4:09 PM
Does it means that MultiDataTriger is not working well ?
regards
Your knowledge is enhanced by that of others.
-
Friday, August 31, 2012 2:19 AMModeratorYes, I think multiDataTrigger does work on this case.
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

