WPF: Changing a control's State using a Trigger
I created a Textbox Template as well as states for it. The states are mainly there so that I can use storyboards to display / hide visual elements.
For example, I have an "Error" States Group, which has transitions such as "New Errors" and "No Errors".
I also have triggers that check if the control's "Validate.HasError" is set to "True" or "False".
I would like to change my control's state by using these triggers, so that I can play the right animation whenever the control fails validation.
In other words, can I change the control's state to "New Errors" or "No Errors" by using these trigger开发者_如何学JAVAs ?
I would preferably like to change the states without having to use code-behind (i.e.: VisualStateManager.GoToState(...))
Instead of using states, I simply assigned different storyboards when the Trigger's actions get activated or deactivated:
<ControlTemplate.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Trigger.ExitActions>
<BeginStoryboard x:Name="HideError_BeginStoryboard" Storyboard="{StaticResource HideError}"/>
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource DisplayError}"/>
</Trigger.EnterActions>
</Trigger>
</ControlTemplate.Triggers>
精彩评论