Problème de Binding dans une animation
J'utilise la modélisation MVVM
J'ai une animation d'un cerle qui se remplit en un temps X.
Une des propriété et de pouvoir définir son temps en seconde.
Dans mon animation je dois binder avec deux propriétés: le temps total (Time qui est une duration) et la moitié du temps (TimeHalf qui est un keytime)
Or bien qu'en debug il passe dans ma propriété, mon animation ne fonctionne pas. Come si le xaml était bindé au mauvais moment
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public Duration Time
{
get { return _time; }
set
{
_time = value;
OnPropertyChanged("Time");
OnPropertyChanged("TimeHalf");
}
}
public KeyTime TimeHalf
{
get {
// var tmp = new TimeSpan(0, 0, 0, 0, (int)_time.TimeSpan.TotalSeconds * 500);
return KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, (int)_time.TimeSpan.TotalSeconds * 500));
}
} |
Code sans binding
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| <Window x:Class="BuzzerGame.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Canvas>
<Path Canvas.Left="150"
Canvas.Top="150"
Fill="Blue"
Stroke="Black">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="0 0"
IsClosed="True">
<LineSegment Point="0 -100" />
<ArcSegment x:Name="arc"
Size="100 100"
SweepDirection="ClockWise" />
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
</Canvas>
<Window.Triggers>
<EventTrigger RoutedEvent="Page.Loaded">
<BeginStoryboard>
<Storyboard TargetName="arc"
AutoReverse="True"
RepeatBehavior="Forever">
<PointAnimationUsingPath
Storyboard.TargetProperty="Point"
Duration="0:0:5">
<PointAnimationUsingPath.PathGeometry>
<PathGeometry
Figures="M 0 -100 A 100 100 0 0 1 0 100
A 100 100 0 0 1 -1 -100" />
</PointAnimationUsingPath.PathGeometry>
</PointAnimationUsingPath>
<BooleanAnimationUsingKeyFrames
Storyboard.TargetProperty="IsLargeArc"
Duration="0:0:5">
<DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="False" />
<DiscreteBooleanKeyFrame KeyTime="0:0:2.5" Value="True" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
</Window> |
Code avec binding
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| <Window x:Class="BuzzerGame.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Canvas>
<Path Canvas.Left="150"
Canvas.Top="150"
Fill="Blue"
Stroke="Black">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="0 0"
IsClosed="True">
<LineSegment Point="0 -100" />
<ArcSegment x:Name="arc"
Size="100 100"
SweepDirection="ClockWise" />
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
</Canvas>
<Window.Triggers>
<EventTrigger RoutedEvent="Page.Loaded">
<BeginStoryboard>
<Storyboard TargetName="arc"
AutoReverse="True"
RepeatBehavior="Forever">
<PointAnimationUsingPath
Storyboard.TargetProperty="Point"
Duration="{Binding Path=Time}">
<PointAnimationUsingPath.PathGeometry>
<PathGeometry
Figures="M 0 -100 A 100 100 0 0 1 0 100
A 100 100 0 0 1 -1 -100" />
</PointAnimationUsingPath.PathGeometry>
</PointAnimationUsingPath>
<BooleanAnimationUsingKeyFrames
Storyboard.TargetProperty="IsLargeArc"
Duration="{Binding Path=Time}">
<DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="False" />
<DiscreteBooleanKeyFrame KeyTime="{Binding Path=TimeHalf}" Value="True" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
</Window> |