Maybe i should start at the beginning. I have 3 knobs that turn when you click them. The knobs turn and turn back like they should. But there's got to be a less redundant way of writing this. My original post was my attempt at cleaning it up, but obviously not working.
With all 3 chunks of code being the same, aside from the name of the knob, how would you put all three under one method and change the name depending on which knob you click? Examples would definitely be appreciated.
Mika, I feel like your solution might be on the right path, but I don't know what to do with the top portion
Here's what the code looks like [edited a bit]:
private bool knobLoc = false;
private void one_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DoubleAnimation da = new DoubleAnimation((knobLoc ? 360 : 0), (knobLoc ? 0 : 360), new Duration(TimeSpan.FromSeconds(0.5)));
RotateTransform rt = new RotateTransform();
if (!knobLoc) { knobLoc = !knobLoc; }
else { knobLoc = false; }
one.RenderTransformOrigin = new Point(0.5, 0.5);
one.RenderTransform = rt;
rt.BeginAnimation(RotateTransform.AngleProperty, da);
}
private void two_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DoubleAnimation da = new DoubleAnimation((knobLoc ? 360 : 0), (knobLoc ? 0 : 360), new Duration(TimeSpan.FromSeconds(0.5)));
RotateTransform rt = new RotateTransform();
if (!knobLoc) { knobLoc = !knobLoc; }
else { knobLoc = false; }
two.RenderTransformOrigin = new Point(0.5, 0.5);
two.RenderTransform = rt;
rt.BeginAnimation(RotateTransform.AngleProperty, da);
}
private void three_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DoubleAnimation da = new DoubleAnimation((knobLoc ? 360 : 0), (knobLoc ? 0 : 360), new Duration(TimeSpan.FromSeconds(0.5)));
RotateTransform rt = new RotateTransform();
if (!knobLoc) { knobLoc = !knobLoc; }
else { knobLoc = false; }
three.RenderTransformOrigin = new Point(0.5, 0.5);
three.RenderTransform = rt;
rt.BeginAnimation(RotateTransform.AngleProperty, da);
}