Click here to Skip to main content
15,879,326 members
Articles / Desktop Programming / WPF

Creating an Animated ContentControl

Rate me:
Please Sign up or sign in to vote.
4.87/5 (38 votes)
15 Dec 2010CPOL4 min read 101.1K   5.9K   56  
Shows how to build a content control which animates transitions between content.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Input;
using GalaSoft.MvvmLight.Command;

namespace AnimatedContentControlSample.ViewModels
{
	/// <summary>
	/// Viewmodel for the main window
	/// </summary>
	class MainWindowViewModel : ViewModelBase
	{
		private object m_content;
		private int m_contentCount;

		/// <summary>
		/// Gets the content that is to be displayed in the view
		/// </summary>
		public object Content
		{
			get { return m_content; }
			set
			{
				if (m_content != value)
				{
					m_content = value;
					RaisePropertyChanged("Content");
				}
			}
		}
		
		public ICommand ChangeContentCommand
		{
			get
			{
				return new RelayCommand(() => Content = new MyContentViewModel(++m_contentCount));
			}
		}
	}
}

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 Code Project Open License (CPOL)


Written By
Software Developer ABB
Sweden Sweden
My name is Isak Savo and I work as a Research Engineer at ABB Corporate Research in Västerås, Sweden. My work is focused around user experience which includes a lot of prototyping of new solutions for user interfaces and user interaction.

While I have a background in C programming in a Linux environment, my daily work is mostly spent in Windows using C# and WPF.

Comments and Discussions