Troubles with GoToStateAction
I have had several problems with the GoToStateAction in different scenarios, and I'm beginning to believe that either the feature is buggy, or that my understanding of it is off.
In this case, I have a datatemplate with an ellipse that is representing a connector. The connector has an IsConnected property... I am using VisualStates and the GoToStateAction with a DataTrigger to switch between the 2 states 'Connected' and 'NotConnected'. However, in this case the state is never set.
I know the model is set up correctly, as trying other binding scenarios with IsConnected works fine. What am I doing wrong?
<DataTemplate x:Key="ConnectorTemplate">
<Grid x:Name="grid">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="ConnectionStates">
<VisualState x:Name="Connected">
<Storyboard>
<ColorAnimation Duration="0" To="#FFEAFFDD" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="ellipse" d:IsOptimized="True"/>
<ColorAnimation Duration="0" To="#FF56992B" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="ellipse" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
<VisualState x:Name="NotConnected"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<VisualStateManager.CustomVisualStateManager>
<ei:ExtendedVisualStateManager/>
</VisualStateManager.CustomVisualStateManager>
<Ellipse x:Name="ellipse"
Height="8"
Width="8">
<i:Interaction.Triggers>
<ei:DataTrigger Binding="{Binding IsConnected}" Value="true开发者_高级运维">
<ei:GoToStateAction StateName="Connected"/>
</ei:DataTrigger>
<ei:DataTrigger Binding="{Binding IsConnected}" Value="false">
<ei:GoToStateAction StateName="NotConnected"/>
</ei:DataTrigger>
</i:Interaction.Triggers>
<Ellipse.Fill>
<RadialGradientBrush Center="0.275,0.262"
GradientOrigin="0.275,0.262"
RadiusX="0.566"
RadiusY="0.566">
<GradientStop Color="#FF333333"
Offset="1" />
<GradientStop Color="#FFC4C4C4" />
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
</Grid>
</DataTemplate>
I think you should set TargetName in GoToStateAction, because by default,if my memory serves me right, Target is associated with GoToStateAction object, in your case - ellipse
GoToStateAction is not triggered when the item is loaded, it only comes in play when the related property is changed (PropertyChanged event is fired).
精彩评论