Witam programistów,
Zacząłem się bawić WPF, w którym używam animacji. Jak najbardziej pokazuje mi się jak również "animuje". Problem w tym, że położenie do jakiego punktu ma się przemieścić jest niezależne od wielkości okna. Trzeci dzień próbuje aby ruch animacji dostosował się do rozmiaru okna, animacja była skalowalna. HELP
<Window x:Class="StacjaKolejowa5.View.Visualization" ... > <Window.Resources> <viewmodel:TrainViewModel x:Key="ViewModel"/> </Window.Resources> <ItemsControl DataContext="{StaticResource ViewModel}" ItemsSource="{Binding Path=Sprites}" Grid.ColumnSpan="2"> <ItemsControl.ItemsPanel > <ItemsPanelTemplate > <Canvas/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl>
public static void MakeTrainMove(Train train, double fromX, double toX, double y) { Canvas.SetTop(train, y); Storyboard storyboard = new Storyboard(); DoubleAnimation animation = new DoubleAnimation(); Storyboard.SetTarget(animation, train); Storyboard.SetTargetProperty(animation, new PropertyPath(Canvas.LeftProperty)); animation.From = fromX; animation.To = toX; animation.Duration = TimeSpan.FromSeconds(3); animation.RepeatBehavior = RepeatBehavior.Forever; animation.AutoReverse = true; storyboard.Children.Add(animation); storyboard.Begin(); }