I would like to set the contents of a button using a trigger in XAML without writing code:
Each time the button is pressed, the contents should be changed: Something like pressing the button for the first time, button contents = "Hello", second press, button contents = "Bye", third time click, button contents = "Hello" again.
<Button x:Name="btn" Content="Hi"> <Button.Triggers> <EventTrigger RoutedEvent="Button.Click"> <BeginStoryboard> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.Target="{x:Reference btn}" Storyboard.TargetProperty="Content"> <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Bye"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> <StopStoryboard> </StopStoryboard> </EventTrigger> </Button.Triggers> </Button>
So, it works to set the button content once before Bye, but how to set it back to Hi the next time you press
I'm also not sure if this is the most efficient way to set a trigger, if you have a better solution, feel free to.
source share