﻿using System.ComponentModel;

namespace MapInfo.MiPro.Samples.SimpleInteractiveCustomFrameExample
{
	/// <summary>
	/// Interaction logic for InteractiveCustomFrameControlContent.xaml
	/// </summary>
	public partial class InteractiveCustomFrameControlContent : INotifyPropertyChanged
	{
		public InteractiveCustomFrameControlContent()
		{
			_initialFrameHeight = 128;
			_initialFrameWidth = 128;
			_scale = 1;
			DataContext = this;
			InitializeComponent();
			NorthArrowText = "";
		}

		private string _northArrowText;

		public string NorthArrowText
		{
			get { return _northArrowText; }
			set
			{
				_northArrowText = value;
				OnPropertyChanged("NorthArrowText");
			}
		}

		
		private double _scale;

		public double Scale
		{
			get
			{
				return _scale;
			}
			set
			{
				  _scale = value;
				OnPropertyChanged("Scale");
				OnPropertyChanged("FrameWidth");
				OnPropertyChanged("FrameHeight");
			}
		}

		private double _initialFrameHeight;
		
		public double FrameHeight
		{
			get { return _initialFrameHeight * Scale ; }
			set
			{
				_initialFrameHeight = value;
				OnPropertyChanged("FrameHeight");
			}
		}

		private double _initialFrameWidth;
		
		public double FrameWidth
		{
			get { return _initialFrameWidth * Scale; }
			set
			{
				_initialFrameWidth = value;
				OnPropertyChanged("FrameWidth");
			}
		}

		public void UpdateDimensions()
		{
			FrameHeight = _initialFrameHeight;
			FrameWidth = _initialFrameWidth;
			OnPropertyChanged("FrameHeight");
			OnPropertyChanged("FrameWidth");
			
		}

		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;

		private void OnPropertyChanged(string name)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(name));
			}
		}

		#endregion
	}
}
