3

I am getting the following error when trying to execute a button clcik event from xaml

<Button x:Name="myButton" Content="Surface History"                    
                HorizontalAlignment="Right">
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MyText" 
                                                           Storyboard.TargetProperty="Text">
                                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Hello" />
                            </ObjectAnimationUsingKeyFrames>

                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>
        <TextBox Name="MyText" Text="Hi"/>

Text Storyboard.TargetProperty path contains nonanimatable property Text.

Himanshu
  • 31,810
  • 31
  • 111
  • 133
Anshu Dutta
  • 491
  • 2
  • 6
  • 18

1 Answers1

0

Text property is Non Animatable dependency property. While creating the dependency property for Text, the UIMetaData IsAnimationProhibited property is set to true which prohibits the Text property to animate.

So Text property cannot be animated. You need to manually set the text from Timer to get this behaviour.

abhishek
  • 2,975
  • 23
  • 38
  • What is the alternate solution? I want to change the text by button clcik without code behind and also without usingCommand binding. I want this to be done in XAML – Anshu Dutta Oct 11 '12 at 06:06
  • The link - http://dotnet.dzone.com/articles/event-based-property-changes - says that this is possible. I am using VS2010. Why am I getting this error when more than one person has stated that this works. Any idea ? – Anshu Dutta Oct 11 '12 at 06:24
  • Nope. It will not work with Text property while other properties like Background, Margin etc works perfectly. I am still searching for a solution. I couldnt find only a XAML way of defining this animation as of now. You can anytime use codebehind to define this or Command interfaces. – abhishek Oct 11 '12 at 06:32