Click here to Skip to main content
15,896,063 members
Articles / Desktop Programming / WPF

Calcium: A modular application toolset leveraging PRISM – Part 1

Rate me:
Please Sign up or sign in to vote.
4.93/5 (70 votes)
1 Jun 2009BSD17 min read 251.9K   208  
Calcium provides much of what one needs to rapidly build a multifaceted and sophisticated modular application. Includes a host of modules and services, and an infrastructure that is ready to use in your next application.
#region File and License Information
/*
<File>
	<Copyright>Copyright © 2007, Daniel Vaughan. All rights reserved.</Copyright>
	<License>
		Redistribution and use in source and binary forms, with or without
		modification, are permitted provided that the following conditions are met:
			* Redistributions of source code must retain the above copyright
			  notice, this list of conditions and the following disclaimer.
			* Redistributions in binary form must reproduce the above copyright
			  notice, this list of conditions and the following disclaimer in the
			  documentation and/or other materials provided with the distribution.
			* Neither the name of the <organization> nor the
			  names of its contributors may be used to endorse or promote products
			  derived from this software without specific prior written permission.

		THIS SOFTWARE IS PROVIDED BY <copyright holder> ''AS IS'' AND ANY
		EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
		WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
		DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
		DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
		(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
		LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
		ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
		(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
		SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
	</License>
	<Owner Name="Daniel Vaughan" Email="dbvaughan@gmail.com"/>
	<CreationDate>2009-05-17 19:03:10Z</CreationDate>
</File>
*/
#endregion

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;

using DanielVaughan.Wpf;

namespace DanielVaughan.Calcium.Client.Gui.Windows
{
	public partial class DesktopShell
	{
		/* Needs refactoring. */
		#region Region Expansion

		GridLength columnRightWidth = new GridLength(1, GridUnitType.Star);

		GridLength rowBannerHeight = GridLength.Auto;
		GridLength columnLeftWidth = GridLength.Auto;
		GridLength rowStatusHeight = GridLength.Auto;

		void Expander_Banner_ExpandChanged(object sender, RoutedEventArgs e)
		{
//			AnimateRow(sender, e, rowDefinition_Banner, ref rowBannerHeight, null);
		}

		void Expander_Left_ExpandChanged(object sender, RoutedEventArgs e)
		{
			ColumnExpandChanged(sender, e, columnDefinition_Left, ref columnLeftWidth, gridSplitter_Left);
		}

		void Expander_Right_ExpandChanged(object sender, RoutedEventArgs e)
		{
			ColumnExpandChanged(sender, e, columnDefinition_Right, ref columnRightWidth, gridSplitter_Right);
		}
        
		/// <summary>Disable the Slider and reset the Height of the status row</summary>
		/// <param name="sender">The expander</param>
		/// <param name="e">The expand or collapsed event</param>
		void Expander_Bottom_ExpandChanged(object sender, RoutedEventArgs e)
		{
			AnimateRow(sender, e, rowDefinition_OutputDisplay, ref rowStatusHeight, gridSplitter_Bottom);
		}

		void ColumnExpandChanged(object sender, RoutedEventArgs e, ColumnDefinition columnDefinition,
			ref GridLength gridLength, GridSplitter gridSplitter)
		{
			if (e.OriginalSource != sender || gridSplitter == null || columnDefinition == null)
			{
				return;
			}

			if (e.RoutedEvent == Expander.CollapsedEvent)
			{
				ContractColumn(columnDefinition, ref gridLength, gridSplitter);
			}
			else
			{
				ExpandColumn(columnDefinition, ref gridLength, gridSplitter);
			}
		}

		void AnimateRow(object sender, RoutedEventArgs e, RowDefinition rowDefinition,
			ref GridLength gridLength, GridSplitter gridSplitter)
		{
			if (e.OriginalSource != sender || rowDefinition == null)
			{
				return;
			}

			if (e.RoutedEvent == Expander.CollapsedEvent)
			{
				ContractRow(rowDefinition, ref gridLength, gridSplitter);
			}
			else
			{
				ExpandRow(rowDefinition, ref gridLength, gridSplitter);
			}
		}

		void ExpandColumn(ColumnDefinition columnDefinition, ref GridLength gridLength, GridSplitter gridSplitter)
		{
			var animation = new GridLengthAnimation
			{
				From = columnDefinition.Width,
				To = gridLength,
				Duration = new Duration(TimeSpan.FromSeconds(.25)),
				FillBehavior = FillBehavior.Stop
			};
			animation.Completed += ((sender, e) =>
			                        	{
											if (gridSplitter != null)
											{
												gridSplitter.IsEnabled = true;
											}
										});
			columnDefinition.BeginAnimation(ColumnDefinition.WidthProperty, animation);
		}

		void ContractColumn(ColumnDefinition definition, ref GridLength gridLength, GridSplitter gridSplitter)
		{
			if (gridSplitter != null)
			{
				gridSplitter.IsEnabled = false;
			}

			gridLength = definition.Width;
			var animation = new GridLengthAnimation
			{
				To = new GridLength(0),
				Duration = new Duration(TimeSpan.FromSeconds(.25))
			};
			definition.BeginAnimation(ColumnDefinition.WidthProperty, animation);
		}

		void ExpandRow(RowDefinition definition, ref GridLength gridLength, GridSplitter gridSplitter)
		{
			var animation = new GridLengthAnimation
			{
				From = definition.Height,
				To = gridLength,
				Duration = new Duration(TimeSpan.FromSeconds(.25)),
				FillBehavior = FillBehavior.Stop
			};

			animation.Completed += ((sender, e) =>
			{
				if (gridSplitter != null)
				{
					gridSplitter.IsEnabled = true;
				}
			});
			definition.BeginAnimation(RowDefinition.HeightProperty, animation);
		}

		void ContractRow(RowDefinition rowDefinition, ref GridLength gridLength, GridSplitter gridSplitter)
		{
			if (gridSplitter != null)
			{
				gridSplitter.IsEnabled = false;
			}

			gridLength = rowDefinition.Height;
			var animation = new GridLengthAnimation
			{
				To = new GridLength(0),
				Duration = new Duration(TimeSpan.FromSeconds(.25))
			};
			rowDefinition.BeginAnimation(RowDefinition.HeightProperty, animation);
		}

		#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 BSD License


Written By
Engineer
Switzerland Switzerland
Daniel is a former senior engineer in Technology and Research at the Office of the CTO at Microsoft, working on next generation systems.

Previously Daniel was a nine-time Microsoft MVP and co-founder of Outcoder, a Swiss software and consulting company.

Daniel is the author of Windows Phone 8 Unleashed and Windows Phone 7.5 Unleashed, both published by SAMS.

Daniel is the developer behind several acclaimed mobile apps including Surfy Browser for Android and Windows Phone. Daniel is the creator of a number of popular open-source projects, most notably Codon.

Would you like Daniel to bring value to your organisation? Please contact

Blog | Twitter


Xamarin Experts
Windows 10 Experts

Comments and Discussions