wpf - fire datatrigger when property changes regardless of new value wpf - fire datatrigger when property changes regardless of new value wpf wpf

wpf - fire datatrigger when property changes regardless of new value


Thanks to the pointers gained from the responses to this question I found the answer was to use an EventTrigger and the TargetUpdated RoutedEvent.

<DataTemplate>    <Border Name="templateBorder">        <TextBlock Name="templateTextBlock" Text="{Binding Path=FirstName, NotifyOnTargetUpdated=True}" />    </Border>    <DataTemplate.Triggers>        <EventTrigger RoutedEvent="Binding.TargetUpdated">            <BeginStoryboard>                <Storyboard AutoReverse="True">                    <DoubleAnimation Storyboard.TargetName="templateTextBlock" Storyboard.TargetProperty="Opacity" To=".1" Duration="0:0:.5" />                </Storyboard>            </BeginStoryboard>        </EventTrigger>    </DataTemplate.Triggers></DataTemplate>

Beyond the EventTrigger, the only other thing that was required was to set 'NotifyOnTargetUpdated=True' when setting up the binding for the textblock.

Thanks.


It looks like you need an EventTrigger "do X when an event occurs" instead of a DataTrigger.

Not tried this myself.. but it should be possible to raise your custom event FirstNameChanged and have the trigger-actions be executed in response to that.


  <Storyboard x:Key="MessageStoryBoardEntry" FillBehavior="Stop">            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">                <EasingDoubleKeyFrame KeyTime="0:0:00.30" Value="0"/>                <EasingDoubleKeyFrame KeyTime="0:0:03" Value="0"/>                <EasingDoubleKeyFrame KeyTime="0:0:03.20" Value="1500"/>            </DoubleAnimationUsingKeyFrames>        </Storyboard>        <Storyboard x:Key="MessageStoryBoardExit" FillBehavior="Stop">            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">                <EasingDoubleKeyFrame KeyTime="0:0:0.001" Value="1500"/>            </DoubleAnimationUsingKeyFrames>        </Storyboard>