1

I am working on ControlTemplate for a Button.
This is my current code which changes button's color.

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1.Styles">

    <ControlTemplate x:Key="ButtonBrushAnimation" TargetType="Button">
        <Grid >
            <TextBlock x:Name="textBlock" Width="80" Height="30" Text="AAA" />

            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">

                    <VisualStateGroup.Transitions>

                        <!--Take one half second to transition to the PointerOver state.-->
                        <VisualTransition To="PointerOver" GeneratedDuration="0:0:0.5"/>

                    </VisualStateGroup.Transitions>

                <VisualState x:Name="PointerOver">
                    <Storyboard>
                        <ColorAnimation Storyboard.TargetName="ButtonBrush" 
                        Storyboard.TargetProperty="Color" To="Red" />
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Grid.Background>
            <SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
        </Grid.Background>
    </Grid>
</ControlTemplate>
</ResourceDictionary>

I want to change text property of textBlock control on PointerOver event.
How can I do it?
Thank you!

1 Answer 1

1

Add StringAnimationUsingKeyFrames to your Storyboard like this:

<Storyboard>
  <ColorAnimation Storyboard.TargetName="ButtonBrush" Storyboard.TargetProperty="Color" To="Red" />
     <StringAnimationUsingKeyFrames Storyboard.TargetName="textBlock" Storyboard.TargetProperty="Text">
         <DiscreteStringKeyFrame Value="BBB"  KeyTime="0:0:0" />
     </StringAnimationUsingKeyFrames>
 </Storyboard>

You can set a KeyTime property value depending on when exactly you need to change the text.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. StringAnimationUsingKeyFrames does not work in Windows Phone 8.1 Any help?
@JacekWojcik sorry, I have no experience with WP :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.