0

I have this code that is works correctly. My target is:

i have a button named "CH1". When i press that, it gets disabled using the style below. Now my question is, can i change the button content to time remaining until it gets back enabled? e.g. when i press it disable for 10 mins and content="00:10:00"and running until 00:00:00. when time passes and it's time to get enabled return to original content "CH1".

<Style TargetType="Button" x:Key="MUaa3">
            <Style.Triggers>
                <EventTrigger RoutedEvent="Button.Click" >
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>
                                <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsEnabled">                                    
                                    <DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="False" /> 
                                    <DiscreteBooleanKeyFrame KeyTime="00:10:00" Value="True" />
                                </BooleanAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </Style.Triggers>

1 Answers1

0

Add a StringAnimationUsingKeyFrames for the Content property of your Button to the Storyboard. (This is in seconds for testing purpose)

                        <Storyboard>
                            <StringAnimationUsingKeyFrames 
                                Storyboard.TargetProperty="(Button.Content)"
                                Duration="0:0:4">
                                <DiscreteStringKeyFrame Value="4" KeyTime="0:0:0" />
                                <DiscreteStringKeyFrame Value="3" KeyTime="0:0:1" />
                                <DiscreteStringKeyFrame Value="2" KeyTime="0:0:2" />
                                <DiscreteStringKeyFrame Value="1" KeyTime="0:0:3" />
                                <DiscreteStringKeyFrame Value="CH1" KeyTime="0:0:4" />
                            </StringAnimationUsingKeyFrames>
                            <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsEnabled">
                                <DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="False" />
                                <DiscreteBooleanKeyFrame KeyTime="00:00:04" Value="True" />
                            </BooleanAnimationUsingKeyFrames>
                        </Storyboard>

If you want to bind an animation property in a style. Here is an question/answer that can be helpful for that:

WPF animation: binding to the "To" attribute of storyboard animation

RolandJS
  • 717
  • 5
  • 5