L'articolo in oggetto è da considerarsi obsoleto.
Prego fare riferimento a
quest'altro articolo.
Beh, un giorno esatto dopo aver descritto il mio Tweener per Silverlight 2.0, rieccomi
qui a mostrare la riedizione completa dell'intera struttura di classi!. Ardisco citarmi...
Gli step futuri prevedono
[...]
...supporto per le strutture Color e Point
Ed eccolo qui.
Per includere nel giro questi tipi e tenere comunque traccia della loro specifica essenza
lungo tutto il processo di tweening
(vedi proprietà CurrentPosition nella classe TweenMotionChangedEventArgs) ho pensato di sfuttare i Tipi Generici (Generics).
Ci troviamo quindi di fronte ad un Tweener<T> o Tweener(Of T) se preferite.
Il codice mostrato ieri necessita, gioco-forza, di una rivisitazione.
Riscriviamone il contenuto nella nuova forma:
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
ITween<Color> tween6 = Tweener<Color>.CreateTween((SolidColorBrush)cnv.Background, SolidColorBrush.ColorProperty, Elastic.EaseOut, Colors.Red, Colors.Black, TimeSpan.FromSeconds(2D));
ITween<double> tween3 = Tweener.CreateTween(cnv, TweenProperty.Angle, Elastic.EaseOut, 0D, -45D, TimeSpan.FromSeconds(4D));
ITween<double> tween = Tweener.CreateTween(cnv, TweenProperty.ScaleY, Bounce.EaseOut, 1, 0.5, TimeSpan.FromSeconds(3D));
ITween<double> tween5 = Tweener.CreateTween(cnv, TweenProperty.AngleX, Linear.EaseNone, 0, -60D, TimeSpan.FromSeconds(3D));
ITween<Point> tween2 = Tweener<Point>.CreateTween(seg, LineSegment.PointProperty, Circ.EaseOutIn, seg.Point, new Point(seg.Point.X, seg.Point.Y+100), TimeSpan.FromSeconds(.9D));
tween.MotionStarted += new EventHandler(tween_MotionStarted);
tween.MotionFinished += new EventHandler(tween_MotionFinished);
tween.MotionChanged += new TweenMotionChangedEventHandler<double>(tween_MotionChanged);
}
void tween_MotionChanged(object sender, TweenMotionChangedEventArgs<double> e)
{
txt.Text += string.Format("\n[{0:T}] value {1}", DateTime.Now, e.CurrentPosition);
}
Aggiungiamo il body del documento XAML dove sono definiti gli oggetti richiamati sopra
(ué! ...nessuna velleità artistica nel layout sotto, puro XAML di test eh!):
<Canvas Background="Black" Width="200" Height="100" x:Name="cnv" VerticalAlignment="Center" HorizontalAlignment="Center">
<Canvas.RenderTransform>
<MatrixTransform Matrix="1,1,-1,1,0,0" />
</Canvas.RenderTransform>
</Canvas>
<Path Stroke="Black" StrokeThickness="1" Fill="Aqua">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="510,50">
<LineSegment Point="211,70" />
<LineSegment Point="660,170" x:Name="seg" />
<LineSegment Point="510,50" />
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
<TextBlock x:Name="txt" TextWrapping="NoWrap"
Text="debug:" Width="Auto" Foreground="Red" FontSize="11" FontFamily="Courier New" />
Nota: il tipo generico in oggetto è richiesto esponga un costruttore vuoto (senza parametri).
Dato che trattiamo "tipi di valore" (Double, Int32, Color, Point... che 'per definizione' offrono un costruttore vuoto)
questo vincolo non è costrittivo come può sembrare. E' altresì piuttosto utile - in un passaggio visibile se
si scarica e si spulcia il codice - per "imbrogliare" il compilatore e recuperare l'effettivo tipo di T.
Conoscere l'effettivo tipo del dato che ci troviamo a trattare, consente di prendere quelle decisioni che
stanno alla base del processo.
/// <summary>
/// Static class that provides tweening functionalities for Silverlight.
/// </summary>
/// <typeparam name="T">The Type of the property to tween.</typeparam>
public static class Tweener<T> where T : new()
Progetti Visual Studio aggiornati (Tweener + Testing Silverlight App) e zippati:
« download code
Take care. Bye.
Feedbacks
no feedbacks yet.