|
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.