Hi ikriv,
I performed a test with your scenario, and verified that we can animate a dependency property which lies in the ViewModel. You may need to derive the ViewModelBase from DependencyObject.
We can then set the DataContext property of the View to the ViewModel, and bind the Target of StoryBoard to the dataContext. Here the code goes:
XAML:
<Button Name="ddd" Click="ddd_Click" Command="{Binding DelRecordCommand}">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard Storyboard.Target="{Binding .}" Storyboard.TargetProperty="Animated" >
<DoubleAnimation From="10.0" To="0.0" BeginTime="0:0:0" Duration="0:0:10" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
abc</Button>
C# code in ViewModel:
public class MainViewModel : ViewModelBase
{
.................................
public static DependencyProperty AnimatedProperty = DependencyProperty.Register("Animated", typeof(double), typeof(MainViewModel),new PropertyMetadata( callBack));
public double Animated
{
get
{
return ((double)(this.GetValue(MainViewModel.AnimatedProperty)));
}
set
{
this.SetValue(MainViewModel.AnimatedProperty, value);
}
}
static void callBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Console.WriteLine(e.NewValue.ToString());
}
............................................................
}
Please let me know if the problem can't be solved, please feel free to let me know.
Best regard,
Bruce Zhou
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.