わかりました、私は本当に不意を突かれる何かに出くわしました。
私は、関係のないいくつかの質問で仲間の開発者を助けていました。彼のプロジェクトでは、テキストをいくつかの TextBlock にアニメーション化していました。そこで、デスクに戻ってプロジェクトを再作成しました (彼の質問に答えるために) が、誤ってTextBlockの代わりにTextBoxを使用してしまいました。テキストがまったくアニメーション化されませんでした。(私はとても助かりました!)
最終的に、彼の xaml は TextBlock を使用しており、私のものは TextBox を使用していることがわかりました。興味深いのは、TextBox を使用していたときに Blend がキー フレームを作成していなかったことです。そのため、TextBlock(s) を使用して Blend で動作するようにし、xaml を手動で変更して、TextBlock(s) を TextBox(es) に変換しました。プロジェクトを実行すると、次のエラーが発生しました。
InvalidOperationException: '(0)' Storyboard.TargetProperty path contains nonanimatable property 'Text'.
まあ、Blend はそれを知っているほど賢く、アニメーションでキー フレームを生成しないようです (TextBox の値を直接変更するだけです)。ブレンドの場合は+1。
それで、問題は次のようになりました: TextBox.Text がアニメーション化できないのはなぜですか? 通常の答えは、アニメーション化している特定のプロパティは DependencyProperty ではないというものです。しかし、そうではありません。TextBox.TextはDependencyProperty です。
だから、今私は当惑しています!TextBox.Text をアニメーション化できないのはなぜですか?
問題を説明するためにいくつかの xaml を含めましょう。次の xaml は機能しますが、TextBlock を使用します。
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="TextBoxTextQuestion.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640"
Height="480"
>
<Window.Resources>
<Storyboard x:Key="animateTextStoryboard">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="textControl">
<DiscreteStringKeyFrame KeyTime="0:0:1" Value="Goodbye"/>
</StringAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource animateTextStoryboard}"/>
</EventTrigger>
</Window.Triggers>
<Grid x:Name="LayoutRoot">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock x:Name="textControl" Text="Hello" FontFamily="Calibri" FontSize="32"/>
<TextBlock Text="World!" Margin="0,25,0,0" FontFamily="Calibri" FontSize="32"/>
</StackPanel>
</Grid>
</Window>
次の xamlは機能せず、TextBox.Text を使用します。
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="TextBoxTextQuestion.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640"
Height="480"
>
<Window.Resources>
<Storyboard x:Key="animateTextStoryboard">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBox.Text)" Storyboard.TargetName="textControl">
<DiscreteStringKeyFrame KeyTime="0:0:1" Value="Goodbye"/>
</StringAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource animateTextStoryboard}"/>
</EventTrigger>
</Window.Triggers>
<Grid x:Name="LayoutRoot">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBox x:Name="textControl" Text="Hello" FontFamily="Calibri" FontSize="32"/>
<TextBox Text="World!" Margin="0,25,0,0" FontFamily="Calibri" FontSize="32"/>
</StackPanel>
</Grid>
</Window>