좋아, 나는 정말로 나를 잡아 끌고있는 뭔가를 만났다.WPF에서 TextBox.Text를 애니메이션화 할 수없는 이유는 무엇입니까?
몇 가지 관련없는 질문으로 동료 개발자를 돕고 있었고 그의 프로젝트에서 TextBlock (s)으로 텍스트 애니메이션을 적용하고있었습니다. 그래서, 나는 다시 그의 책상에 가서 그의 질문에 답하기 위해 프로젝트를 다시 만들었지 만, 실수로 TextBlock 대신에 TextBox을 사용했습니다. 내 텍스트가 전혀 애니메이션이 아니 었습니다! (많은 도움, 나는 있었다!)
결국, 그의 xaml이 TextBlock을 사용하고 있고 TextBox를 사용하고 있다는 것을 알았습니다. 흥미로운 점은 TextBox를 사용할 때 블렌드가 키 프레임을 만들지 못했기 때문입니다. 그래서 TextBlock을 사용하여 Blend에서 작업 한 다음 xaml을 직접 수정하여 TextBlock을 TextBox로 변환했습니다. 혼합 애니메이션에서 키 프레임을 생성 알고 ...가 아니라 똑똑 것처럼 그냥 것 (
InvalidOperationException: '(0)' Storyboard.TargetProperty path contains nonanimatable property 'Text'.
글쎄, 그것은 보인다 내가 프로젝트를 실행하면, 다음과 같은 오류가 발생했습니다 TextBox에서 직접 값을 수정하십시오.) 블렌드 +1.
그래서 질문이 생겼습니다. 왜 TextBox.Text를 애니메이션으로 만들 수 없습니까? 보통 대답은 애니메이트하는 특정 속성이 DependencyProperty가 아니라는 것입니다. 그러나이 경우, TextBox.Text 은 DependencyProperty입니다.
그래서 지금 당황하고 있습니다! 왜 TextBox.Text에 애니메이션을 적용 할 수 없습니까?
문제를 설명하기 위해 일부 xaml을 포함 시키십시오. 다음 xaml은 작동하지만 TextBlock (s)을 사용합니다.
<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>
흥미 롭다 ... 결코 이것에 대한 필요성을 갖지는 않았지만, 항상 그렇다고 추정했다. 바라건대 누군가가 대답을하기를 바랍니다. 미안해. 도울 수 없어. –
감사합니다. 나는 학문적 인 질문이 조금있다 ...하지만 나는 애니메이션 할 수없는 DependencyProperty를 보는 것이 매우 궁금하다. – cplotts