Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

WPF: A TimeLineControl

, 14 Apr 2010
Simple WPF TimeLineControl That I Think May Be Useful
TimeLineDemoProject.zip
TimeLineDemoProject
TimeLineControl
bin
Debug
TimeLineControl.dll
Transitionals.dll
Controls
Common
EventArgs
StateVisualisers
Days
Decades
Months
SpecificDay
Years
ExtensionMethods
Images
close.png
leftArrow.png
Interfaces
Lib
Transitionals.dll
Misc
Properties
Settings.settings
Resources
States
TimeLineControl.csproj.user
TimeLineDemoProject
bin
Debug
TimeLineControl.dll
TimeLineDemoProject.exe
TimeLineDemoProject.vshost.exe
TimeLineDemoProject.vshost.exe.manifest
Transitionals.dll
DemoViewModel
Images
description.png
itemtime.png
Properties
Settings.settings
TimeLineDemoProject.csproj.user
TimeLineDemoProject.suo
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TimeLineControl
{
    /// <summary>
    /// State visualiser for <c>ViewingMonthsState</c>.
    /// This creates a new <c>MonthView</c> passing it the
    /// List of ITimeLineItem to draw
    /// </summary>
    public partial class ViewingMonthsStateControl : 
        UserControl, IStateControl, IDisposable
    {
        #region Ctor
        public ViewingMonthsStateControl()
        {
            InitializeComponent();
        }
        #endregion

        #region Public Properties

        public Action NavigateUpAction { get; set; }
        public Action NavigateDownAction { get; set; }
        public DateTime CurrentViewingDate { get; set; }
        public TimeLineControl Parent { private get; set; }



        #region ItemsDataTemplate

        /// <summary>
        /// ItemsDataTemplate Dependency Property
        /// </summary>
        public static readonly DependencyProperty ItemsDataTemplateProperty =
            DependencyProperty.Register("ItemsDataTemplate", typeof(DataTemplate),
            typeof(ViewingMonthsStateControl),
                new FrameworkPropertyMetadata((DataTemplate)null,
                    new PropertyChangedCallback(OnItemsDataTemplateChanged)));

        /// <summary>
        /// Gets or sets the ItemsDataTemplate property.  
        /// </summary>
        public DataTemplate ItemsDataTemplate
        {
            get { return (DataTemplate)GetValue(ItemsDataTemplateProperty); }
            set { SetValue(ItemsDataTemplateProperty, value); }
        }

        /// <summary>
        /// Handles changes to the ItemsDataTemplate property.
        /// </summary>
        private static void OnItemsDataTemplateChanged(DependencyObject d, 
            DependencyPropertyChangedEventArgs e)
        {
        }
        #endregion

        #endregion

        #region Public Methods
        public void ReDraw(List<ITimeLineItem> timeLineItems)
        {
            if (timeLineItems != null)
            {

                grid.Children.Clear();
                grid.Height = this.Height - 50;

                CreateBreadCrumb();

                lblDetails.Content = String.Format("Jan-Dec {0}",
                    CurrentViewingDate.Year);

                MonthView yv = new MonthView()
                {
                    ItemsDataTemplate = this.ItemsDataTemplate,
                    Height = this.Height - spButtons.Height,
                    Width = grid.Width,
                    CurrentViewingDate = CurrentViewingDate,
                    TimeLineItems = timeLineItems
                };
                yv.ViewDateEvent += yv_ViewDateEvent;
                yv.Loaded += (s, e) =>
                {
                    yv.Draw();
                };
                grid.Children.Add(yv);
            }
        }
        #endregion

        #region Private Methods
        private void yv_ViewDateEvent(object sender, DateEventArgs e)
        {
            CurrentViewingDate = e.CurrentViewingDate;
            NavigateDownAction();
        }

        private void NavigateUp_Click(object sender, RoutedEventArgs e)
        {
            NavigateUpAction();
        }

        private void CreateBreadCrumb()
        {
            breadCrumbContainer.Children.Clear();
            BreadCrumb bc = new BreadCrumb();
            bc.Parent = this.Parent;
            bc.NavigateArgs = new NavigateArgs(this.CurrentViewingDate,
                NavigatingToSource.MonthsOfYear);
            breadCrumbContainer.Children.Add(bc);
        }
        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            foreach (MonthView yv in grid.Children)
            {
                yv.ViewDateEvent -= yv_ViewDateEvent;
            }
        }

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

Share

About the Author

Sacha Barber
Software Developer (Senior)
United Kingdom United Kingdom
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)
 
- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence
 
Both of these at Sussex University UK.
 
Award(s)

I am lucky enough to have won a few awards for Zany Crazy code articles over the years

  • Microsoft C# MVP 2014
  • Codeproject MVP 2014
  • Microsoft C# MVP 2013
  • Codeproject MVP 2013
  • Microsoft C# MVP 2012
  • Codeproject MVP 2012
  • Microsoft C# MVP 2011
  • Codeproject MVP 2011
  • Microsoft C# MVP 2010
  • Codeproject MVP 2010
  • Microsoft C# MVP 2009
  • Codeproject MVP 2009
  • Microsoft C# MVP 2008
  • Codeproject MVP 2008
  • And numerous codeproject awards which you can see over at my blog

| Advertise | Privacy | Mobile
Web02 | 2.8.140921.1 | Last Updated 14 Apr 2010
Article Copyright 2010 by Sacha Barber
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid