本文介绍了当TextBox更改属性时,WPF在边框上应用Storyboard DoubleAnimation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当特定文本框的值发生变化时,如何在边框上应用故事板动画。以下是我的xaml代码。
<Border x:Name="ContentBorder">
<StackPanel>
<TextBox Text="{Binding LevelView_ID, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnTargetUpdated=True}">
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<EventTrigger RoutedEvent="Binding.TargetUpdated">
<BeginStoryboard>
<Storyboard AutoReverse="True">
<DoubleAnimation
Storyboard.TargetName="ContentBorder"
Storyboard.TargetProperty="Opacity"
To=".1"
Duration="0:0:.5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<TextBox Text="{Binding LevelView_Title}" />
</StackPanel>
</Border>
注意: 以上
代码显示Storyboard.TargetName =" ContentBorder"
targetname属性无法在style setter
targetname property cannot be set on a style setter
推荐答案
与
"a-storyboard-tree-in-a样式无法指定TargetName删除TargetName" :
<Window.Resources>
<Storyboard x:Key="contentBorderAnimation" AutoReverse="True">
<DoubleAnimation
Storyboard.Target="{Binding ElementName=ContentBorder}" <!---bind the target to an element name--->
Storyboard.TargetProperty="Opacity"
To=".1"
Duration="0:0:.5" >
</DoubleAnimation>
</Storyboard>
<Style x:Key="borderAnimatedText" TargetType="TextBox">
<Style.Triggers>
<EventTrigger RoutedEvent="TextBox.TextChanged">
<EventTrigger.Actions>
<BeginStoryboard Storyboard="{StaticResource contentBorderAnimation}">
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
.....
<Border x:Name="ContentBorder">
<StackPanel>
<TextBox Style="{StaticResource borderAnimatedText}" Text="{Binding LevelView_ID, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnTargetUpdated=True}">
</TextBox>
<TextBox Text="{Binding LevelView_Title}" />
</StackPanel>
</Border>
希望有所帮助;
hope it help;
这篇关于当TextBox更改属性时,WPF在边框上应用Storyboard DoubleAnimation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!