gpt4 book ai didi

c# - Storyboard 仅针对第二个条件触发一次

转载 作者:行者123 更新时间:2023-11-30 17:28:10 25 4
gpt4 key购买 nike

我有一个按钮,在该按钮上运行 TextBlock MultiDataTrigger,但在每次单击按钮时它只运行两次。

解释:第一个默认 TextBlock 文本断开连接,然后有两个 MultiDataTriggers 满足条件运行,然后在另一个 MultiDataTrigger 再次点击按钮后,但在此之后没有 Storyboard 动画工作。

文本 block

<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 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>

最佳答案

使用单一条件 IsChecked 而不是检查文本框文本或按下的按钮,不要使用简单的 Button,而是使用 ToggleButton 并在其上应用您的 Button 样式。

你可以这样使用它:

您的TextBlock

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

ToggleButton 而不是 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>

您的 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>

关于c# - Storyboard 仅针对第二个条件触发一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53434537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com