Dopytam może jeszcze w tym temacie zamiast zakładać nowy bo dotyczy to cały czas tego samego projektu, mamy taki kod:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
Random random = new Random();
public MainWindow()
{
InitializeComponent();
}
private void startButtoN_Click(object sender, RoutedEventArgs e)
{
AddEnemy();
}
private void AddEnemy()
{
ContentControl enemy = new ContentControl();
enemy.Template = Resources["EnemyTemplate"] as ControlTemplate;
AnimateEnemy(enemy, 0, playArea.ActualWidth - 100, "(Canvas.Left");
AnimateEnemy(enemy, random.Next((int)playArea.ActualHeight - 100),
random.Next((int)playArea.ActualHeight - 100), "(Canvas.Top)");
playArea.Children.Add(enemy);
}
private void AnimateEnemy(ContentControl enemy, double from, double to, string propertyToAnimate)
{
Storyboard storyboard = new Storyboard() { AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever };
DoubleAnimation animation = new DoubleAnimation()
{
From = from,
To = to,
Duration = new Duration(TimeSpan.FromSeconds(random.Next(4, 6)))
};
Storyboard.SetTarget(animation, enemy);
Storyboard.SetTargetProperty(animation, propertyToAnimate); //55
storyboard.Children.Add(animation);
storyboard.Begin();
}
}
}
Wyrzuca mi dwa błędy w 55 linijce:
1. Error 1 The best overloaded method match for System.Windows.Media.Animation.Storyboard.SetTargetProperty(System.Windows.DependencyObject, System.Windows.PropertyPath)' has some invalid arguments.
2. Error 2 Argument 2: cannot convert from 'string' to 'System.Windows.PropertyPath'
Wie ktoś może jak to poprawić by było dobrze?
PS Chodzi o tą linię, nie wiem jak ją "Wyróżnić"
Storyboard.SetTargetProperty(animation, propertyToAnimate);
dodanie znacznika <code class="none">
- @furious programming