I have trouble with animations. I have to control my double animation from asynchronous threads. Seperate threads will change uklepe value asynchronously, animations will play as a result of changes. That's what i tried but i am still getting this error even i used Dispatcher :
The Calling Thread Cannot Access This Object Because A Different Thread Owns It
protected bool üstklepe = false;
public bool uklepe
{
get
{
return üstklepe;
}
set
{
if (üstklepe == false && value == true)
{
var da = new DoubleAnimation(0, 90, new Duration(TimeSpan.FromMilliseconds(100)));
var rt = new RotateTransform(0, 0, 0);
Dispatcher.Invoke(() => {Ustklepe.RenderTransform = rt;});
Dispatcher.Invoke(() => {Ustklepe.RenderTransformOrigin = new Point(0, 0);});
Dispatcher.Invoke(() => {rt.BeginAnimation(RotateTransform.AngleProperty, da);});
RadialGradientBrush myBrush = new RadialGradientBrush();
myBrush.GradientOrigin = new Point(0.35, 0.65);
myBrush.GradientStops.Add(new GradientStop(Colors.White, 0.0));
myBrush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF91D393"), 0.916));
//SolidColorBrush Brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF91D393"));
Dispatcher.Invoke(() => { Ustklepe.Fill = myBrush; });
üstklepe = value;
}
else if (üstklepe == true && value == false)
{
var da = new DoubleAnimation(90, 0, new Duration(TimeSpan.FromMilliseconds(100)));
var rt = new RotateTransform(0, 0, 0);
Dispatcher.Invoke(() => {Ustklepe.RenderTransform = rt;});
Dispatcher.Invoke(() => {Ustklepe.RenderTransformOrigin = new Point(0, 0);});
Dispatcher.Invoke(() => {rt.BeginAnimation(RotateTransform.AngleProperty, da);});
RadialGradientBrush myBrush = new RadialGradientBrush();
myBrush.GradientOrigin = new Point(0.35, 0.65);
myBrush.GradientStops.Add(new GradientStop(Colors.White, 0.0));
myBrush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FFFF2F33"), 0.916));
//SolidColorBrush Brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFF2F33"));
Dispatcher.Invoke(() => { Ustklepe.Fill = myBrush; });
üstklepe = value;
}
else
üstklepe = value;
}
}