Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Issue in Triggering event when multiple values changed in View Model

$
0
0

Hi there, I am creating an animation where I have to rotate a needle. So in the XAML, I have 2 bindings. One for the angle to be rotated and second is the duration. (Duration is the one I load from config file, so cannot be hard coded in the XAML. My XAML looks as shown below...

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    MinWidth="300" MinHeight="300"><Grid><Path Name="needle" StrokeThickness="2" Width="110" Height="12"  Panel.ZIndex="55" HorizontalAlignment="Center" Data="M1,1 L1,10 L156,6 z" Stretch="Fill" RenderTransformOrigin="0,0.5" Margin="165,146,55,148" Fill="#FFC00000" 
        Tag="{Binding Value, UpdateSourceTrigger=PropertyChanged,NotifyOnTargetUpdated=True}"><Path.RenderTransform><RotateTransform Angle="{Binding Value}" CenterX="0" CenterY="0"/></Path.RenderTransform><Path.Triggers><EventTrigger RoutedEvent="Binding.TargetUpdated"><BeginStoryboard><Storyboard><DoubleAnimation 
                                Storyboard.TargetProperty="(Path.RenderTransform).(RotateTransform.Angle)" Duration="{Binding Duration}"/></Storyboard></BeginStoryboard></EventTrigger></Path.Triggers></Path></Grid></UserControl>

Now, the problem is I am able to rotate the needle properly based on the 'Value' binded to the control. But the animation seems to be taking some default duration despite me assigning some value to the 'Duration' in my ViewModel.

 

Even I am doing trick to perform the animation. I set the Path.Tag value as my rotation angle and based on 'Binding.TargetUpdated' Trigger I do animation'. But how do I trigger when both 'Value' (Angle Value) and 'Duration' changed in ViewModel? I thought about using a MultiBinding but if i use it I have to create a MultiConverter as well. In my scenario I cannot have the code behind (XXX.xaml.cs file) I need to have only the xaml file. Somebody please tell me how do deal with this scenario... Thanks in advance...



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>