Click here to Skip to main content
12,290,716 members (29,906 online)
Click here to Skip to main content

Stats

28.5K views
819 downloads
22 bookmarked
Posted

Clearer – A Gesture-Driven Windows 8 To-Do Application

, 9 Oct 2012 CPOL
This article describes my experiences of porting a novel gesture-driven Windows Phone app to Windows 8.
using System;
using ClearStyle.ViewModel;
using LinqToVisualTree;
using System.Linq;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml;

namespace ClearStyle.Interactions
{
  /// <summary>
  /// A base class for interactions.
  /// </summary>
  public abstract class InteractionBase : IInteraction
  {
    private bool _isActive = false;

    protected ItemsControl _todoList;
    protected ObservableCollectionEx<ToDoItem> _todoItems;
    private ScrollViewer _scrollViewer;

    public virtual void Initialise(ItemsControl todoList, ObservableCollectionEx<ToDoItem> todoItems)
    {
      _todoList = todoList;
      _todoItems = todoItems;

      IsEnabled = true;
    }

    protected ScrollViewer ScrollViewer
    {
      get
      {
        if (_scrollViewer == null)
        {
          _scrollViewer = _todoList.Descendants<ScrollViewer>()
                              .Cast<ScrollViewer>()
                              .SingleOrDefault();
        }
        return _scrollViewer;
      }
    }

    protected virtual void ScrollViewerLocated(ScrollViewer scrollViewer)
    {
    }

    public virtual void AddElement(FrameworkElement rootElement, FrameworkElement transformElement)
    {
    }

    public bool IsActive
    {
      get
      {
        return _isActive;
      }
      set
      {
        _isActive = value;

        if (_isActive == true)
        {
          if (Activated != null)
          {
            Activated(this, EventArgs.Empty);
          }
        }
        else
        {
          if (DeActivated != null)
          {
            DeActivated(this, EventArgs.Empty);
          }
        }
      }
    }

    public bool IsEnabled { get; set; }
    
    public event EventHandler Activated;

    public event EventHandler DeActivated;

    /// <summary>
    /// Some interactions involve adding transformations or performing other visual modifications
    /// to items within the list. When the interaction is complete, we need to remove these and return
    /// the list to its original state. This method simply forces the ItemsControl to re-render all items.
    /// </summary>
    protected void RefreshView()
    {
      StackPanel itemsPanel = _todoList.Descendants<StackPanel>().OfType<StackPanel>().Single();

      var old = itemsPanel.ChildrenTransitions;
      itemsPanel.ChildrenTransitions = null;
      _todoItems.Reset();

      itemsPanel.InvokeOnNextLayoutUpdated(() =>
      itemsPanel.ChildrenTransitions = old);
    }
  }
}

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

Colin Eberhardt
Architect Scott Logic
United Kingdom United Kingdom
I am CTO at ShinobiControls, a team of iOS developers who are carefully crafting iOS charts, grids and controls for making your applications awesome.

I am a Technical Architect for Visiblox which have developed the world's fastest WPF / Silverlight and WP7 charts.

I am also a Technical Evangelist at Scott Logic, a provider of bespoke financial software and consultancy for the retail and investment banking, stockbroking, asset management and hedge fund communities.

Visit my blog - Colin Eberhardt's Adventures in .NET.

Follow me on Twitter - @ColinEberhardt

-

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160518.1 | Last Updated 10 Oct 2012
Article Copyright 2012 by Colin Eberhardt
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid