WPF 在尝试简单的角色动画时引发异常

本文关键字:动画 异常 角色 简单 WPF | 更新日期: 2023-09-27 18:29:01

An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '54' and line position '22'.

尝试运行以下 XAML 部分时遇到该错误

         <Border Background="AliceBlue"  CornerRadius="33" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    VerticalAlignment="top" HorizontalAlignment="Center" BorderThickness="0"  BorderBrush="#ccc" Padding="10" SnapsToDevicePixels="True" Width="298" Margin="113,12,117,0">
        <TextBlock FontFamily="Comic Sans MS"  
                   FontSize="25" 
                   TextWrapping="Wrap" 
                   x:Name="txtBlkThanks" 
                   Foreground="Gray"                        
                   Width="198" Height="39"
                   >
            Clap your hands
            <TextBlock.Triggers>
                <EventTrigger RoutedEvent="TextBlock.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <StringAnimationUsingKeyFrames Storyboard.TargetName="txtBlkThanks"
                                                           Storyboard.TargetProperty="(TextBlock.Content)"
                                                           Duration="0:0:8"
                                                           FillBehavior="HoldEnd">
                                <DiscreteStringKeyFrame Value="" KeyTime="0:0:0"/>
                                <DiscreteStringKeyFrame Value="C" KeyTime="0:0:1"/>                                                                        
                                <DiscreteStringKeyFrame Value="Cl" KeyTime="0:0:1.5"/>                                                                        
                                <DiscreteStringKeyFrame Value="Cla" KeyTime="0:0:2"/>                                                                        
                                <DiscreteStringKeyFrame Value="Clap" KeyTime="0:0:2.5"/>                                                                        
                                <DiscreteStringKeyFrame Value="Clap y" KeyTime="0:0:3"/>                                                                        
                                <DiscreteStringKeyFrame Value="Clap yo" KeyTime="0:0:3.5"/>                                                                        
                                <DiscreteStringKeyFrame Value="Clap you" KeyTime="0:0:4"/>
                                <DiscreteStringKeyFrame Value="Clap your" KeyTime="0:0:4.5"/>                                                                        
                                <DiscreteStringKeyFrame Value="Clap your h" KeyTime="0:0:5"/>                                                                        
                                <DiscreteStringKeyFrame Value="Clap your ha" KeyTime="0:0:5.5"/>                                                                        
                                <DiscreteStringKeyFrame Value="Clap your han" KeyTime="0:0:6"/>                                                                        
                                <DiscreteStringKeyFrame Value="Clap your hand" KeyTime="0:0:6.5"/>                                                                        
                                <DiscreteStringKeyFrame Value="Clap your hands" KeyTime="0:0:7"/>                                                                      
                            </StringAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </TextBlock.Triggers>
        </TextBlock>
     </Border>

我想在加载文本块时,加载窗口时制作"拍手"动画。谢谢

WPF 在尝试简单的角色动画时引发异常

我认为问题是您正在尝试绑定到TextBlock.Content。但是TextBlock具有"Text"属性,它不是ContentControl。因此,如果您将其更改为"文本",您应该没问题。