Storyboard Triggers only once for second condition











up vote
3
down vote

favorite
3












I have a button on which Click, TextBlock MultiDataTrigger runs but on every button click it runs only twice.



Explaination: First Default TextBlock Text is Disconnected then there are two MultiDataTriggers out of which satisfies the condition runs and then after another MultiDataTrigger on again button click but after this no Storyboard animation works.



Textblock



<TextBlock x:Name="abctxt" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Text="Disconnected">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=sbbtn, Path=IsPressed}" Value="True" />
<Condition Binding="{Binding ElementName=abctxt, Path=Text}" Value="Connected" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource DisconnectedTextChange}"/>
</MultiDataTrigger.EnterActions>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=sbbtn, Path=IsPressed}" Value="True" />
<Condition Binding="{Binding ElementName=abctxt, Path=Text}" Value="Disconnected" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ConnectedTextChange}"/>
</MultiDataTrigger.EnterActions>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>


Button



<Button x:Name="sbbtn" />


Storyboard



<Storyboard x:Key="ConnectedTextChange" x:Name="ConnectedTextChange">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Connected"/>
</StringAnimationUsingKeyFrames>
</Storyboard>

<Storyboard x:Key="DisconnectedTextChange" x:Name="DisconnectedTextChange">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Disconnected"/>
</StringAnimationUsingKeyFrames>
</Storyboard>









share|improve this question
























  • It seems that the text is hold as “Connected” by the ConnectedTextChange Storyboard so the other Storyboard cannot change it back to “Disconnected”.
    – kennyzx
    Nov 24 at 4:36










  • @kennyzx have try this? Any suggestion, what should i do?
    – Code Learner
    Nov 24 at 8:39










  • do you have to use an animation (Storyboard)? Or do you just want to change the Text in response to the button click? By default, a Storyboard holds the final value when the Storyboard is completed.
    – kennyzx
    Nov 24 at 8:43












  • @kennyzx no! i have to use storyboard, actually i have a another control(Rectangle which slide through margins using storyboard) also which also have same condition as textblock but both textblock and rectangle begin storyboard only once
    – Code Learner
    Nov 24 at 8:54










  • @sachinshinde try my approach does same thing correctly.
    – Shubham Sahu
    Nov 27 at 9:27















up vote
3
down vote

favorite
3












I have a button on which Click, TextBlock MultiDataTrigger runs but on every button click it runs only twice.



Explaination: First Default TextBlock Text is Disconnected then there are two MultiDataTriggers out of which satisfies the condition runs and then after another MultiDataTrigger on again button click but after this no Storyboard animation works.



Textblock



<TextBlock x:Name="abctxt" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Text="Disconnected">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=sbbtn, Path=IsPressed}" Value="True" />
<Condition Binding="{Binding ElementName=abctxt, Path=Text}" Value="Connected" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource DisconnectedTextChange}"/>
</MultiDataTrigger.EnterActions>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=sbbtn, Path=IsPressed}" Value="True" />
<Condition Binding="{Binding ElementName=abctxt, Path=Text}" Value="Disconnected" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ConnectedTextChange}"/>
</MultiDataTrigger.EnterActions>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>


Button



<Button x:Name="sbbtn" />


Storyboard



<Storyboard x:Key="ConnectedTextChange" x:Name="ConnectedTextChange">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Connected"/>
</StringAnimationUsingKeyFrames>
</Storyboard>

<Storyboard x:Key="DisconnectedTextChange" x:Name="DisconnectedTextChange">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Disconnected"/>
</StringAnimationUsingKeyFrames>
</Storyboard>









share|improve this question
























  • It seems that the text is hold as “Connected” by the ConnectedTextChange Storyboard so the other Storyboard cannot change it back to “Disconnected”.
    – kennyzx
    Nov 24 at 4:36










  • @kennyzx have try this? Any suggestion, what should i do?
    – Code Learner
    Nov 24 at 8:39










  • do you have to use an animation (Storyboard)? Or do you just want to change the Text in response to the button click? By default, a Storyboard holds the final value when the Storyboard is completed.
    – kennyzx
    Nov 24 at 8:43












  • @kennyzx no! i have to use storyboard, actually i have a another control(Rectangle which slide through margins using storyboard) also which also have same condition as textblock but both textblock and rectangle begin storyboard only once
    – Code Learner
    Nov 24 at 8:54










  • @sachinshinde try my approach does same thing correctly.
    – Shubham Sahu
    Nov 27 at 9:27













up vote
3
down vote

favorite
3









up vote
3
down vote

favorite
3






3





I have a button on which Click, TextBlock MultiDataTrigger runs but on every button click it runs only twice.



Explaination: First Default TextBlock Text is Disconnected then there are two MultiDataTriggers out of which satisfies the condition runs and then after another MultiDataTrigger on again button click but after this no Storyboard animation works.



Textblock



<TextBlock x:Name="abctxt" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Text="Disconnected">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=sbbtn, Path=IsPressed}" Value="True" />
<Condition Binding="{Binding ElementName=abctxt, Path=Text}" Value="Connected" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource DisconnectedTextChange}"/>
</MultiDataTrigger.EnterActions>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=sbbtn, Path=IsPressed}" Value="True" />
<Condition Binding="{Binding ElementName=abctxt, Path=Text}" Value="Disconnected" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ConnectedTextChange}"/>
</MultiDataTrigger.EnterActions>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>


Button



<Button x:Name="sbbtn" />


Storyboard



<Storyboard x:Key="ConnectedTextChange" x:Name="ConnectedTextChange">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Connected"/>
</StringAnimationUsingKeyFrames>
</Storyboard>

<Storyboard x:Key="DisconnectedTextChange" x:Name="DisconnectedTextChange">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Disconnected"/>
</StringAnimationUsingKeyFrames>
</Storyboard>









share|improve this question















I have a button on which Click, TextBlock MultiDataTrigger runs but on every button click it runs only twice.



Explaination: First Default TextBlock Text is Disconnected then there are two MultiDataTriggers out of which satisfies the condition runs and then after another MultiDataTrigger on again button click but after this no Storyboard animation works.



Textblock



<TextBlock x:Name="abctxt" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Text="Disconnected">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=sbbtn, Path=IsPressed}" Value="True" />
<Condition Binding="{Binding ElementName=abctxt, Path=Text}" Value="Connected" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource DisconnectedTextChange}"/>
</MultiDataTrigger.EnterActions>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=sbbtn, Path=IsPressed}" Value="True" />
<Condition Binding="{Binding ElementName=abctxt, Path=Text}" Value="Disconnected" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ConnectedTextChange}"/>
</MultiDataTrigger.EnterActions>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>


Button



<Button x:Name="sbbtn" />


Storyboard



<Storyboard x:Key="ConnectedTextChange" x:Name="ConnectedTextChange">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Connected"/>
</StringAnimationUsingKeyFrames>
</Storyboard>

<Storyboard x:Key="DisconnectedTextChange" x:Name="DisconnectedTextChange">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Disconnected"/>
</StringAnimationUsingKeyFrames>
</Storyboard>






c# wpf xaml storyboard






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 at 10:13

























asked Nov 22 at 15:54









Code Learner

407




407












  • It seems that the text is hold as “Connected” by the ConnectedTextChange Storyboard so the other Storyboard cannot change it back to “Disconnected”.
    – kennyzx
    Nov 24 at 4:36










  • @kennyzx have try this? Any suggestion, what should i do?
    – Code Learner
    Nov 24 at 8:39










  • do you have to use an animation (Storyboard)? Or do you just want to change the Text in response to the button click? By default, a Storyboard holds the final value when the Storyboard is completed.
    – kennyzx
    Nov 24 at 8:43












  • @kennyzx no! i have to use storyboard, actually i have a another control(Rectangle which slide through margins using storyboard) also which also have same condition as textblock but both textblock and rectangle begin storyboard only once
    – Code Learner
    Nov 24 at 8:54










  • @sachinshinde try my approach does same thing correctly.
    – Shubham Sahu
    Nov 27 at 9:27


















  • It seems that the text is hold as “Connected” by the ConnectedTextChange Storyboard so the other Storyboard cannot change it back to “Disconnected”.
    – kennyzx
    Nov 24 at 4:36










  • @kennyzx have try this? Any suggestion, what should i do?
    – Code Learner
    Nov 24 at 8:39










  • do you have to use an animation (Storyboard)? Or do you just want to change the Text in response to the button click? By default, a Storyboard holds the final value when the Storyboard is completed.
    – kennyzx
    Nov 24 at 8:43












  • @kennyzx no! i have to use storyboard, actually i have a another control(Rectangle which slide through margins using storyboard) also which also have same condition as textblock but both textblock and rectangle begin storyboard only once
    – Code Learner
    Nov 24 at 8:54










  • @sachinshinde try my approach does same thing correctly.
    – Shubham Sahu
    Nov 27 at 9:27
















It seems that the text is hold as “Connected” by the ConnectedTextChange Storyboard so the other Storyboard cannot change it back to “Disconnected”.
– kennyzx
Nov 24 at 4:36




It seems that the text is hold as “Connected” by the ConnectedTextChange Storyboard so the other Storyboard cannot change it back to “Disconnected”.
– kennyzx
Nov 24 at 4:36












@kennyzx have try this? Any suggestion, what should i do?
– Code Learner
Nov 24 at 8:39




@kennyzx have try this? Any suggestion, what should i do?
– Code Learner
Nov 24 at 8:39












do you have to use an animation (Storyboard)? Or do you just want to change the Text in response to the button click? By default, a Storyboard holds the final value when the Storyboard is completed.
– kennyzx
Nov 24 at 8:43






do you have to use an animation (Storyboard)? Or do you just want to change the Text in response to the button click? By default, a Storyboard holds the final value when the Storyboard is completed.
– kennyzx
Nov 24 at 8:43














@kennyzx no! i have to use storyboard, actually i have a another control(Rectangle which slide through margins using storyboard) also which also have same condition as textblock but both textblock and rectangle begin storyboard only once
– Code Learner
Nov 24 at 8:54




@kennyzx no! i have to use storyboard, actually i have a another control(Rectangle which slide through margins using storyboard) also which also have same condition as textblock but both textblock and rectangle begin storyboard only once
– Code Learner
Nov 24 at 8:54












@sachinshinde try my approach does same thing correctly.
– Shubham Sahu
Nov 27 at 9:27




@sachinshinde try my approach does same thing correctly.
– Shubham Sahu
Nov 27 at 9:27












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Instead of checking textbox text or button pressed go with single condition IsChecked,
Instead of using a simple Button use ToggleButton and apply your Button style on it.



You can use it like this way:



Your TextBlock



<TextBlock x:Name="abctxt" Text="Disconnected" />


ToggleButton Instead of Button



<ToggleButton x:Name="sbbtn"> <!-- Also Apply Your Style For making your ToggleButton looks like your Button -->
<ToggleButton.Triggers>
<EventTrigger RoutedEvent="ToggleButton.Checked">
<BeginStoryboard Storyboard="{StaticResource ConnectedTextChange}" />
</EventTrigger>
<EventTrigger RoutedEvent="ToggleButton.Unchecked">
<BeginStoryboard Storyboard="{StaticResource DisconnectedTextChange}" />
</EventTrigger>
</ToggleButton.Triggers>




Your Storyboard



<!-- Here i set TargetName also -->
<Storyboard x:Key="ConnectedTextChange" x:Name="ConnectedTextChange" Storyboard.TargetName="abctxt">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Connected"/>
</StringAnimationUsingKeyFrames>




<Storyboard x:Key="DisconnectedTextChange" x:Name="DisconnectedTextChange" Storyboard.TargetName="abctxt">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Disconnected"/>
</StringAnimationUsingKeyFrames>
</Storyboard>





share|improve this answer

















  • 1




    Thanks' its works as intended, also thanks for suggestion of using toggle button.
    – Code Learner
    Nov 27 at 9:57










  • @sachinshinde Glad it worked
    – Shubham Sahu
    Nov 27 at 9:58











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434537%2fstoryboard-triggers-only-once-for-second-condition%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Instead of checking textbox text or button pressed go with single condition IsChecked,
Instead of using a simple Button use ToggleButton and apply your Button style on it.



You can use it like this way:



Your TextBlock



<TextBlock x:Name="abctxt" Text="Disconnected" />


ToggleButton Instead of Button



<ToggleButton x:Name="sbbtn"> <!-- Also Apply Your Style For making your ToggleButton looks like your Button -->
<ToggleButton.Triggers>
<EventTrigger RoutedEvent="ToggleButton.Checked">
<BeginStoryboard Storyboard="{StaticResource ConnectedTextChange}" />
</EventTrigger>
<EventTrigger RoutedEvent="ToggleButton.Unchecked">
<BeginStoryboard Storyboard="{StaticResource DisconnectedTextChange}" />
</EventTrigger>
</ToggleButton.Triggers>




Your Storyboard



<!-- Here i set TargetName also -->
<Storyboard x:Key="ConnectedTextChange" x:Name="ConnectedTextChange" Storyboard.TargetName="abctxt">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Connected"/>
</StringAnimationUsingKeyFrames>




<Storyboard x:Key="DisconnectedTextChange" x:Name="DisconnectedTextChange" Storyboard.TargetName="abctxt">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Disconnected"/>
</StringAnimationUsingKeyFrames>
</Storyboard>





share|improve this answer

















  • 1




    Thanks' its works as intended, also thanks for suggestion of using toggle button.
    – Code Learner
    Nov 27 at 9:57










  • @sachinshinde Glad it worked
    – Shubham Sahu
    Nov 27 at 9:58















up vote
1
down vote



accepted










Instead of checking textbox text or button pressed go with single condition IsChecked,
Instead of using a simple Button use ToggleButton and apply your Button style on it.



You can use it like this way:



Your TextBlock



<TextBlock x:Name="abctxt" Text="Disconnected" />


ToggleButton Instead of Button



<ToggleButton x:Name="sbbtn"> <!-- Also Apply Your Style For making your ToggleButton looks like your Button -->
<ToggleButton.Triggers>
<EventTrigger RoutedEvent="ToggleButton.Checked">
<BeginStoryboard Storyboard="{StaticResource ConnectedTextChange}" />
</EventTrigger>
<EventTrigger RoutedEvent="ToggleButton.Unchecked">
<BeginStoryboard Storyboard="{StaticResource DisconnectedTextChange}" />
</EventTrigger>
</ToggleButton.Triggers>




Your Storyboard



<!-- Here i set TargetName also -->
<Storyboard x:Key="ConnectedTextChange" x:Name="ConnectedTextChange" Storyboard.TargetName="abctxt">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Connected"/>
</StringAnimationUsingKeyFrames>




<Storyboard x:Key="DisconnectedTextChange" x:Name="DisconnectedTextChange" Storyboard.TargetName="abctxt">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Disconnected"/>
</StringAnimationUsingKeyFrames>
</Storyboard>





share|improve this answer

















  • 1




    Thanks' its works as intended, also thanks for suggestion of using toggle button.
    – Code Learner
    Nov 27 at 9:57










  • @sachinshinde Glad it worked
    – Shubham Sahu
    Nov 27 at 9:58













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Instead of checking textbox text or button pressed go with single condition IsChecked,
Instead of using a simple Button use ToggleButton and apply your Button style on it.



You can use it like this way:



Your TextBlock



<TextBlock x:Name="abctxt" Text="Disconnected" />


ToggleButton Instead of Button



<ToggleButton x:Name="sbbtn"> <!-- Also Apply Your Style For making your ToggleButton looks like your Button -->
<ToggleButton.Triggers>
<EventTrigger RoutedEvent="ToggleButton.Checked">
<BeginStoryboard Storyboard="{StaticResource ConnectedTextChange}" />
</EventTrigger>
<EventTrigger RoutedEvent="ToggleButton.Unchecked">
<BeginStoryboard Storyboard="{StaticResource DisconnectedTextChange}" />
</EventTrigger>
</ToggleButton.Triggers>




Your Storyboard



<!-- Here i set TargetName also -->
<Storyboard x:Key="ConnectedTextChange" x:Name="ConnectedTextChange" Storyboard.TargetName="abctxt">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Connected"/>
</StringAnimationUsingKeyFrames>




<Storyboard x:Key="DisconnectedTextChange" x:Name="DisconnectedTextChange" Storyboard.TargetName="abctxt">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Disconnected"/>
</StringAnimationUsingKeyFrames>
</Storyboard>





share|improve this answer












Instead of checking textbox text or button pressed go with single condition IsChecked,
Instead of using a simple Button use ToggleButton and apply your Button style on it.



You can use it like this way:



Your TextBlock



<TextBlock x:Name="abctxt" Text="Disconnected" />


ToggleButton Instead of Button



<ToggleButton x:Name="sbbtn"> <!-- Also Apply Your Style For making your ToggleButton looks like your Button -->
<ToggleButton.Triggers>
<EventTrigger RoutedEvent="ToggleButton.Checked">
<BeginStoryboard Storyboard="{StaticResource ConnectedTextChange}" />
</EventTrigger>
<EventTrigger RoutedEvent="ToggleButton.Unchecked">
<BeginStoryboard Storyboard="{StaticResource DisconnectedTextChange}" />
</EventTrigger>
</ToggleButton.Triggers>




Your Storyboard



<!-- Here i set TargetName also -->
<Storyboard x:Key="ConnectedTextChange" x:Name="ConnectedTextChange" Storyboard.TargetName="abctxt">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Connected"/>
</StringAnimationUsingKeyFrames>




<Storyboard x:Key="DisconnectedTextChange" x:Name="DisconnectedTextChange" Storyboard.TargetName="abctxt">
<StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" AccelerationRatio="1">
<DiscreteStringKeyFrame KeyTime="0:0:0.8" Value="Disconnected"/>
</StringAnimationUsingKeyFrames>
</Storyboard>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 27 at 9:23









Shubham Sahu

1,0831727




1,0831727








  • 1




    Thanks' its works as intended, also thanks for suggestion of using toggle button.
    – Code Learner
    Nov 27 at 9:57










  • @sachinshinde Glad it worked
    – Shubham Sahu
    Nov 27 at 9:58














  • 1




    Thanks' its works as intended, also thanks for suggestion of using toggle button.
    – Code Learner
    Nov 27 at 9:57










  • @sachinshinde Glad it worked
    – Shubham Sahu
    Nov 27 at 9:58








1




1




Thanks' its works as intended, also thanks for suggestion of using toggle button.
– Code Learner
Nov 27 at 9:57




Thanks' its works as intended, also thanks for suggestion of using toggle button.
– Code Learner
Nov 27 at 9:57












@sachinshinde Glad it worked
– Shubham Sahu
Nov 27 at 9:58




@sachinshinde Glad it worked
– Shubham Sahu
Nov 27 at 9:58


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434537%2fstoryboard-triggers-only-once-for-second-condition%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Trompette piccolo

Slow SSRS Report in dynamic grouping and multiple parameters

Simon Yates (cyclisme)