In WPF toolkit datagrid I have a data trigger bound to opacity of cell element.
When UpVisibility
changes to 1 the path become visible and the animation starts to fade it to 0. Which works.
However my problem now - if I need to prematurely stop/cancel the fading and am setting UpVisibility
to 0 the Path is still visible and fading as nothing happened....
How to drop opacity to 0 instantly using MyValue object ?
<Path Data="M 5,0 0,10 10,10" Height="10" Width="10" Fill="Green" Opacity="{Binding MyValue[0].UpVisibility}" Margin="5,0,5,0">
<Path.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding MyValue[0].UpVisibility}" Value="1.0">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="1.0" To="0.0" Duration="0:0:10" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Path.Style>
</Path>
Storyboards can also be stopped using the
ExitAction
on aDataTrigger
, which is called when the bound value changes out of the target state. Just give yourBeginStoryboard
a name, and reference it in aStopStoryboard
action, like so:This may be more appropriate than starting a second storyboard to stop or mask a different storyboard.
Have you tried something like this (untested example):
I set the animation duration to 0 to be instant. And if you don't define the From property you are instructing WPF to start in the current DependencyProperty value, so it will transition smoothly.
If you need to reset animation in code behind you usually do such call:
But how to do it in XAML according to MVVM? Answer is:
To call animation in ViewModel we can do:
Also make sure that binding property (Vanishing in my case) calls INotifyPropertyChanged to notify view about new value