私の Silverlight 4 アプリケーションでは、カスタム コントロールを作成し、Visual States incl を追加しました。トランジション。状態変更が初めて実行されるとき、遷移はなく、ある状態から別の状態への急速な変化のみです (まったく遷移がない場合と同様)。以降の状態変更はすべて、期待どおりに遷移を実行します。コンストラクターで初期状態を設定しようとしましたが、これは役に立ちません。初めて移行がないのはなぜですか?
これが私のカスタム コントロールのコードです。
[TemplateVisualState(GroupName="CommonState", Name="Expand")]
[TemplateVisualState(GroupName="CommonState", Name="Collapse")]
public class CollapsibleContainer : ContentControl
{
public CollapsibleContainer()
{
this.DefaultStyleKey = typeof(CollapsibleContainer);
VisualStateManager.GoToState(this, "Expand", false);
}
private void BorderHeader_Click(object sender, MouseButtonEventArgs args)
{
if (_contentPresenter.Visibility == Visibility.Collapsed)
{
_contentPresenter.Visibility = Visibility.Visible;
VisualStateManager.GoToState(this, "Expand", true);
}
else
{
_contentPresenter.Visibility = Visibility.Collapsed;
VisualStateManager.GoToState(this, "Collapse", true);
}
}
}
Visual States の定義は次のとおりです。
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonState">
<VisualState x:Name="Expand" />
<VisualState x:Name="Collapse">
<Storyboard>
<DoubleAnimation Duration="0" To="180" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="ImageArrowNormal" d:IsOptimized="True"/>
<DoubleAnimation Duration="0" To="180" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="ImageArrowHover" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
<VisualStateGroup.Transitions>
<VisualTransition x:Name="Expand2Collapse" From="Expand" To="Collapse">
<Storyboard>
<DoubleAnimation Duration="0:0:0.3" To="180" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="ImageArrowNormal"/>
<DoubleAnimation Duration="0:0:0.3" To="180" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="ImageArrowHover"/>
</Storyboard>
</VisualTransition>
<VisualTransition x:Name="Collapse2Expand" From="Collapse" To="Expand">
<Storyboard>
<DoubleAnimation Duration="0:0:0.3" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="ImageArrowNormal"/>
<DoubleAnimation Duration="0:0:0.3" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="ImageArrowHover"/>
</Storyboard>
</VisualTransition>
</VisualStateGroup.Transitions>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>