WPF, Two Textboxes, one trigger, one animation?
I have a window with two textboxes sitting in the grid. The grid contains one trigger which fires an animation when the text in either of the textboxes changes. Problem. I want the textbox which is updated to be affected by the animation, currently I have to set StoryBoard.TargetName to the name of a textbox to make it work.
Here's a snippet:
<Window x:Class="WpfApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="229" Width="413"
<Grid Width="395" Height="185">
<Grid.Triggers>
<EventTrigger RoutedEvent="TextBox.TextChanged">
<BeginStoryboard>
<Storyboard>
<ColorAnimation AutoReverse="False" Duration="0:0:1" From="Orange" To="White"
Storyboard.TargetName="txtBox1" AccelerationRatio="1"
Storyboard.TargetProperty="(TextBox.Background).(SolidColorBrush.Color)"
FillBehavior="HoldEnd">
</ColorAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
<TextBox x:Name="txtBox1" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Left" Margin="8,128,0,33" Width="378" FontFamily="Consolas" Text="{Binding Path=Output}" Height="23" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="8,150,0,0" Name="textBox1开发者_开发知识库" VerticalAlignment="Top" Width="378" />
</Grid>
Thank you
put the trigger in named style (for TextBox
type) in a resource area, then use that style for each TextBox
Create a MultiTrigger that also checks for "IsFocused".
精彩评论