Click here to Skip to main content
15,917,061 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: How to know DataGrid sorting changed (any Event)? Pin
Frank W. Wu28-Jan-10 5:42
Frank W. Wu28-Jan-10 5:42 
GeneralRe: How to know DataGrid sorting changed (any Event)? Pin
Covean28-Jan-10 5:52
Covean28-Jan-10 5:52 
QuestionAnimation in code behind Pin
V.27-Jan-10 23:53
professionalV.27-Jan-10 23:53 
AnswerRe: Animation in code behind Pin
ProtoBytes28-Jan-10 3:28
ProtoBytes28-Jan-10 3:28 
GeneralRe: Animation in code behind Pin
V.28-Jan-10 3:56
professionalV.28-Jan-10 3:56 
GeneralRe: Animation in code behind Pin
V.28-Jan-10 23:58
professionalV.28-Jan-10 23:58 
GeneralRe: Animation in code behind Pin
ProtoBytes29-Jan-10 3:45
ProtoBytes29-Jan-10 3:45 
GeneralRe: Animation in code behind Pin
V.29-Jan-10 4:03
professionalV.29-Jan-10 4:03 
Reformat? No way, that would come out more ugly, but here's the code with additional comments.

Note I continued playing with it.

		private void btn_start_Click(object sender, RoutedEventArgs e)
		{
			if(sb == null){

				sb = new Storyboard();
//create first animation object, this one will change the angle: the duration is done ugly here, but since it is a test.
//The values to, from and duration are taken from a textbox value.
				da = new DoubleAnimation();
				da.From = Convert.ToInt32(txtbox_anglefrom.Text);
				da.To = Convert.ToInt32(txtbox_angleto.Text);
				string [] timespan = txtbox_duration.Text.Split(new string [] {":"}, StringSplitOptions.None);
				da.Duration = new Duration(new TimeSpan(Convert.ToInt32(timespan[0]), Convert.ToInt32(timespan[1]), Convert.ToInt32(timespan[2])));
				da.RepeatBehavior = RepeatBehavior.Forever;  //how long should it continue
				da.AutoReverse = true;  // reverses the animation instead of restarting from the beginning
				//Here we set the properties of the rectangle for the animation, 0.5 = 50% so center rectangle.
				rectangle_animation.RenderTransform = new RotateTransform();
				rectangle_animation.RenderTransformOrigin = new Point(0.5, 0.5);

//create second animation object, this one will change the color			
				ca = new ColorAnimation();
				ca.From = Colors.Red;
				ca.To = Colors.Blue;
				//ca.Duration = new Duration(new TimeSpan(0, 0, 10));
				ca.Duration = new Duration(new TimeSpan(Convert.ToInt32(timespan[0]), Convert.ToInt32(timespan[1]), Convert.ToInt32(timespan[2])));
				ca.RepeatBehavior = RepeatBehavior.Forever;
				ca.AutoReverse = true;

//if Fill is null, we get an error, but if we assign a value, it is frozen.  (go figure)
				if(rectangle_animation.Fill == null){
					rectangle_animation.Fill = new SolidColorBrush();
					//if you use following line to initiate, the Fill property is "frozen".
					//rectangle_animation.Fill = Brushes.Red;
				}											//end if

//here we 'register' a name for the animation property and assign that to the StoryBoard object.
//this for both animations.  IOW "create a name 'rectangle_angle' for the rectangle_animation.RenderTransform property and use this property for the animation: then add to the storyboard".  Or at least, that's how I see it.
				this.RegisterName("rectangle_angle", rectangle_animation.RenderTransform);
				Storyboard.SetTargetName(da, "rectangle_angle");
				Storyboard.SetTargetProperty(da, new PropertyPath(RotateTransform.AngleProperty));
				

				this.RegisterName("rectangle_brush", (SolidColorBrush)rectangle_animation.Fill);
				Storyboard.SetTargetName(ca, "rectangle_brush");
				Storyboard.SetTargetProperty(ca, new PropertyPath(SolidColorBrush.ColorProperty));

//Add the actual animations to the Storyboard
				sb.Children.Add(da);
				sb.Children.Add(ca);

				sb.Begin(this, true); //Boolean must be set to true if we want to pause and stop.
				txtbox_duration.IsEnabled = false;
				txtbox_anglefrom.IsEnabled = false;
				txtbox_angleto.IsEnabled = false;
			}
			else{
				sb.Resume(this);
			}
			btn_stop.IsEnabled = true;
			btn_start.IsEnabled = false;
		}

		private void btn_stop_Click(object sender, RoutedEventArgs e)
		{
			if(sb != null){
				sb.Pause(this);
			}
			btn_stop.IsEnabled = false;
			btn_start.IsEnabled = true;
		}

		private void btn_close_Click(object sender, RoutedEventArgs e)
		{
			this.Close();
		}

		private void btn_restart_Click(object sender, RoutedEventArgs e) {
//in order to redefine the storyboard later, unregister the names.
			sb.Stop(this);
			sb = null;
			this.UnregisterName("rectangle_angle");
			this.UnregisterName("rectangle_brush");
			btn_stop.IsEnabled = false;
			btn_start.IsEnabled = true;
			txtbox_duration.IsEnabled = true;
			txtbox_anglefrom.IsEnabled = true;
			txtbox_angleto.IsEnabled = true;

		}


there, I hope that's useful Smile | :)

V.

Stop smoking so you can: Enjoy longer the money you save.
Moviereview Archive

AnswerRe: Animation in code behind Pin
ProtoBytes29-Jan-10 4:08
ProtoBytes29-Jan-10 4:08 
GeneralRe: Animation in code behind Pin
V.29-Jan-10 4:12
professionalV.29-Jan-10 4:12 
QuestionInput date as UK format Pin
surfluds27-Jan-10 3:41
surfluds27-Jan-10 3:41 
AnswerRe: Input date as UK format Pin
Abhinav S27-Jan-10 5:30
Abhinav S27-Jan-10 5:30 
QuestionVS 2008 WPF Designer Bug? Pin
PMBT27-Jan-10 1:24
PMBT27-Jan-10 1:24 
QuestionDrag and drop between ListBox items and Grid cells in WPF? Pin
mittalpa26-Jan-10 13:59
mittalpa26-Jan-10 13:59 
AnswerRe: Drag and drop between ListBox items and Grid cells in WPF? Pin
ProtoBytes27-Jan-10 7:17
ProtoBytes27-Jan-10 7:17 
QuestionPlaying games over internet with WPF apps? Pin
mittalpa26-Jan-10 13:56
mittalpa26-Jan-10 13:56 
AnswerRe: Playing games over internet with WPF apps? Pin
Mark Salsbery27-Jan-10 5:28
Mark Salsbery27-Jan-10 5:28 
AnswerRe: Playing games over internet with WPF apps? Pin
nagisetty128-Jan-10 1:20
nagisetty128-Jan-10 1:20 
QuestionWays to identify which cell was clicked on WPF Grid? Pin
mittalpa26-Jan-10 13:54
mittalpa26-Jan-10 13:54 
AnswerRe: Ways to identify which cell was clicked on WPF Grid? Pin
Mark Salsbery27-Jan-10 5:22
Mark Salsbery27-Jan-10 5:22 
QuestionMVVM application ? Pin
Mohammad Dayyan25-Jan-10 21:38
Mohammad Dayyan25-Jan-10 21:38 
AnswerRe: MVVM application ? Pin
ProtoBytes29-Jan-10 4:04
ProtoBytes29-Jan-10 4:04 
QuestionHelp with deployement Pin
ToddHileHoffer25-Jan-10 8:04
ToddHileHoffer25-Jan-10 8:04 
AnswerRe: Help with deployement Pin
Mark Salsbery25-Jan-10 14:22
Mark Salsbery25-Jan-10 14:22 
GeneralRe: Help with deployement Pin
ToddHileHoffer25-Jan-10 14:57
ToddHileHoffer25-Jan-10 14:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.