Click here to Skip to main content
15,897,704 members
Articles / Desktop Programming / WPF

Reflection Studio - Part 1 - Introduction: Architecture and Design

Rate me:
Please Sign up or sign in to vote.
4.83/5 (23 votes)
22 Sep 2010GPL36 min read 60.1K   6.9K   111  
Reflection Studio is a "developer" application for assembly, database, performance, and code generation, written in C# under WPF 4.0.
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Threading;
using System;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Collections.Generic;

namespace ReflectionStudio.Controls
{
	public class WaitSpin : Control
	{
		static WaitSpin()
		{
			FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(WaitSpin),
				new FrameworkPropertyMetadata(typeof(WaitSpin)));
		}

		#region --------------------DEPENDENCY PROPERTIES--------------------

		public static readonly DependencyProperty ThicknessProperty =
			   DependencyProperty.Register("Thickness", typeof(int), typeof(WaitSpin));

		public int Thickness
		{
			get { return (int)GetValue(ThicknessProperty); }
			set { SetValue(ThicknessProperty, value); }
		}
		#endregion

		#region Data
		private DispatcherTimer _animationTimer;
		private RotateTransform SpinnerRotate;
        #endregion

		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();

			SpinnerRotate = this.Template.FindName("PART_SpinnerRotate", this) as RotateTransform;

			Canvas cs= this.Template.FindName("PART_Frame", this) as Canvas;
			cs.IsVisibleChanged += new DependencyPropertyChangedEventHandler(HandleVisibleChanged);
			cs.SizeChanged += new SizeChangedEventHandler(HandleSizeChanged);

			//Initialize();
			if (_animationTimer == null)
			{
				_animationTimer = new DispatcherTimer(DispatcherPriority.ContextIdle, Dispatcher);
				_animationTimer.Interval = new TimeSpan(0, 0, 0, 0, 120);
			}
		}

		void HandleSizeChanged(object sender, SizeChangedEventArgs e)
		{
		}

        #region Private Methods
        private void Start()
        {
            _animationTimer.Tick += HandleAnimationTick;
            _animationTimer.Start();
        }

        private void Stop()
        {
            _animationTimer.Stop();
            _animationTimer.Tick -= HandleAnimationTick;
        }

        private void HandleAnimationTick(object sender, EventArgs e)
        {
            SpinnerRotate.Angle = (SpinnerRotate.Angle + 10) % 360;
        }

		private void CreateCircle()
		{
			const double offset = Math.PI;
			const double step = Math.PI * 2 / 10.0;

			for (int i = 0; i < 9; i++)
			{
				Ellipse e = this.Template.FindName("PART_Ellipse" + i, this) as Ellipse;
				SetPosition(e, offset, i, step);
			}
		}

		//private void Initialize()
		//{
		//    if (_animationTimer == null)
		//    {
		//        _animationTimer = new DispatcherTimer(DispatcherPriority.ContextIdle, Dispatcher);
		//        _animationTimer.Interval = new TimeSpan(0, 0, 0, 0, 75);
		//    }
		//    const double offset = Math.PI;
		//    const double step = Math.PI * 2 / 10.0;

		//    for (int i = 0; i < 9; i++)
		//        SetPosition(listEllipse[i], offset, i, step);

		//    //SetPosition(C1, offset, 1.0, step);
		//    //SetPosition(C2, offset, 2.0, step);
		//    //SetPosition(C3, offset, 3.0, step);
		//    //SetPosition(C4, offset, 4.0, step);
		//    //SetPosition(C5, offset, 5.0, step);
		//    //SetPosition(C6, offset, 6.0, step);
		//    //SetPosition(C7, offset, 7.0, step);
		//    //SetPosition(C8, offset, 8.0, step);
		//}

		private void SetPosition(Ellipse ellipse, double offset, double posOffSet, double step)
		{
			ellipse.SetValue(Canvas.LeftProperty, 50.0 + Math.Sin(offset + posOffSet * step) * 50.0);
			ellipse.SetValue(Canvas.TopProperty, 50 + Math.Cos(offset + posOffSet * step) * 50.0);
		}

        protected void HandleVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            bool isVisible = (bool)e.NewValue;

            if (isVisible)
                Start();
            else
                Stop();
        }
        #endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Architect
France France
WPF and MVVM fan, I practice C # in all its forms from the beginning of the NET Framework without mentioning C ++ / MFC and other software packages such as databases, ASP, WCF, Web & Windows services, Application, and now Core and UWP.
In my wasted hours, I am guilty of having fathered C.B.R. and its cousins C.B.R. for WinRT and UWP on the Windows store.
But apart from that, I am a great handyman ... the house, a rocket stove to heat the jacuzzi and the last one: a wood oven for pizza, bread, and everything that goes inside

https://guillaumewaser.wordpress.com/
https://fouretcompagnie.wordpress.com/

Comments and Discussions