2

Button.Triggerで単純なDoubleAnimationを使用しています。Animation Fromは、ルート要素のActualHeightにバインドされています。これは期待どおりに機能します。

次に、ストーリーボードをVisualStateManagerに移動しようとしました。今、WPFは文句を言います:

System.Windows.Dataエラー:2:ターゲット要素の支配的なFrameworkElementまたはFrameworkContentElementが見つかりません。BindingExpression:Path = ActualWidth; DataItem = null; ターゲット要素は「DoubleAnimation」(HashCode = 29201322)です。ターゲットプロパティは'To'です(タイプ'Nullable`1')

VisualStateManager.VisualStateGroups / VisualState内のアニメーションでバインディングを使用することはできませんか?

そうではないようです。ストーリーボードをリソースに移動することで問題を修正しました。これで、GameToTitleは機能しますが、TitleToGameは失敗します。

これが予想されるかどうかを知りたいのですが。

関連するXAML:

<Grid x:Name="MainInterface">
    <Grid.Resources>
        <Storyboard x:Key="GameToTitle">
            <DoubleAnimation Storyboard.TargetName="GameScreenInterface" Storyboard.TargetProperty="(Control.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)" From="0" To="{Binding Path=ActualHeight, ElementName=MainInterface}" Duration="0:0:0.2"/>
            <DoubleAnimation Storyboard.TargetName="TitleScreenInterface" Storyboard.TargetProperty="(Control.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)" From="{Binding Path=ActualHeight, ElementName=MainInterface, Converter={Converters:InverseConverter}}" To="0" Duration="0:0:0.2"/>
        </Storyboard>
    </Grid.Resources>
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup>
            <VisualState x:Name="TitleScreenState" Storyboard="{StaticResource ResourceKey=GameToTitle}"/>
            <VisualState x:Name="GameScreenState">
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="GameScreenInterface" Storyboard.TargetProperty="(Control.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)" From="{Binding Path=ActualHeight, ElementName=MainInterface}" To="0" Duration="0:0:0.2"/>
                        <DoubleAnimation Storyboard.TargetName="TitleScreenInterface" Storyboard.TargetProperty="(Control.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)" From="0" To="{Binding Path=ActualHeight, ElementName=MainInterface, Converter={Converters:InverseConverter}}" Duration="0:0:0.2"/>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <View:TitleScreen x:Name="TitleScreenInterface"/>
    <View:GameScreen x:Name="GameScreenInterface" />
</Grid>
4

1 に答える 1

3

質問のコメントにあるように、バインディングを含むストーリーボードは、バインディングが機能するために、VisualStateGroup内でインラインではなくリソースとして宣言する必要があります。これは、VisualStatesがVisualTreeの一部ではないためです。一方、リソースはそうです。

Snoop(または同様のユーティリティ)を使用してアプリケーションのビジュアルツリーを確認することで、これを自分で視覚化できます。リソースノードはSnoop内のビジュアルツリーに表示されますが、VisualStatesは表示されません。

ビジュアルツリーに表示されるストーリーボード。

于 2012-12-13T13:34:03.137 に答える