当TextBox更改属性时,WPF在边框上应用Storyboard DoubleAnimation

编程入门 行业动态 更新时间:2024-10-21 06:11:03
本文介绍了当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

推荐答案

你好,

hello,

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

本文发布于:2023-11-11 23:24:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579825.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:边框   属性   TextBox   WPF   DoubleAnimation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!