|
|
@ -6,10 +6,9 @@ |
|
|
|
|
|
|
|
|
namespace Perspex.Controls |
|
|
namespace Perspex.Controls |
|
|
{ |
|
|
{ |
|
|
using System.Linq; |
|
|
using System.Collections; |
|
|
using System.Reactive.Linq; |
|
|
using System.Collections.Generic; |
|
|
using Perspex.Controls.Generators; |
|
|
using Perspex.Controls.Generators; |
|
|
using Perspex.Controls.Presenters; |
|
|
|
|
|
using Perspex.Controls.Primitives; |
|
|
using Perspex.Controls.Primitives; |
|
|
using Perspex.Input; |
|
|
using Perspex.Input; |
|
|
|
|
|
|
|
|
@ -20,28 +19,77 @@ namespace Perspex.Controls |
|
|
return new TreeItemContainerGenerator<TreeViewItem>(this); |
|
|
return new TreeItemContainerGenerator<TreeViewItem>(this); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//protected override void OnPointerPressed(PointerEventArgs e)
|
|
|
protected override void MoveSelection(FocusNavigationDirection direction) |
|
|
//{
|
|
|
{ |
|
|
// IVisual source = (IVisual)e.Source;
|
|
|
// TODO: Up and down movement is a *HACK* and probably pretty slow. Probably needs
|
|
|
// ContentPresenter contentPresenter = source.GetVisualAncestors()
|
|
|
// rewriting at some point.
|
|
|
// .OfType<ContentPresenter>()
|
|
|
if (this.SelectedItem != null) |
|
|
// .FirstOrDefault();
|
|
|
{ |
|
|
|
|
|
switch (direction) |
|
|
// if (contentPresenter != null)
|
|
|
{ |
|
|
// {
|
|
|
case FocusNavigationDirection.Up: |
|
|
// TreeViewItem container = contentPresenter.TemplatedParent as TreeViewItem;
|
|
|
{ |
|
|
|
|
|
var list = this.Flatten(); |
|
|
// if (container != null)
|
|
|
var index = list.IndexOf(this.SelectedItem); |
|
|
// {
|
|
|
|
|
|
// foreach (var i in this.GetVisualDescendents().OfType<TreeViewItem>())
|
|
|
if (index > 0) |
|
|
// {
|
|
|
{ |
|
|
// i.IsSelected = i == container;
|
|
|
this.SelectedItem = list[index - 1]; |
|
|
// }
|
|
|
} |
|
|
|
|
|
break; |
|
|
// this.SelectedItem = this.ItemContainerGenerator.GetItemForContainer(container);
|
|
|
} |
|
|
// }
|
|
|
|
|
|
// }
|
|
|
case FocusNavigationDirection.Down: |
|
|
|
|
|
{ |
|
|
//}
|
|
|
var list = this.Flatten(); |
|
|
|
|
|
var index = list.IndexOf(this.SelectedItem); |
|
|
|
|
|
|
|
|
|
|
|
if (index + 1 < list.Count) |
|
|
|
|
|
{ |
|
|
|
|
|
this.SelectedItem = list[index + 1]; |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case FocusNavigationDirection.Left: |
|
|
|
|
|
{ |
|
|
|
|
|
var node = (TreeViewItem)this.ItemContainerGenerator.GetContainerForItem(this.SelectedItem); |
|
|
|
|
|
node.IsExpanded = false; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case FocusNavigationDirection.Right: |
|
|
|
|
|
{ |
|
|
|
|
|
var node = (TreeViewItem)this.ItemContainerGenerator.GetContainerForItem(this.SelectedItem); |
|
|
|
|
|
node.IsExpanded = true; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<object> Flatten() |
|
|
|
|
|
{ |
|
|
|
|
|
var result = new List<object>(); |
|
|
|
|
|
this.Flatten(this.Items, result); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Flatten(IEnumerable items, List<object> result) |
|
|
|
|
|
{ |
|
|
|
|
|
if (items != null) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (object item in items) |
|
|
|
|
|
{ |
|
|
|
|
|
var container = (TreeViewItem)this.ItemContainerGenerator.GetContainerForItem(item); |
|
|
|
|
|
result.Add(item); |
|
|
|
|
|
|
|
|
|
|
|
if (container.IsExpanded) |
|
|
|
|
|
{ |
|
|
|
|
|
this.Flatten(container.Items, result); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|