5 using System.Windows.Controls;
6 using System.Windows.Controls.Primitives;
7 using System.Windows.Input;
8 using System.Windows.Media;
10 using SiliconStudio.Presentation.Controls;
12 namespace SiliconStudio.Presentation.Behaviors
16 private Selector selector;
21 while (parent != null)
23 parent = VisualTreeHelper.GetParent(parent);
24 if (parent is Selector)
30 throw new InvalidOperationException(
"Unable to find a parent Selector to the associated VirtualizingTilePanel.");
33 selector = (Selector)parent;
35 selector.IsSynchronizedWithCurrentItem =
true;
36 KeyboardNavigation.SetDirectionalNavigation(selector, KeyboardNavigationMode.None);
38 selector.PreviewKeyDown += OnAssociatedObjectKeyDown;
43 selector.PreviewKeyDown -= OnAssociatedObjectKeyDown;
47 private void OnAssociatedObjectKeyDown(
object sender, KeyEventArgs e)
49 if (selector.SelectedIndex == -1 || selector.Items.Count == 0)
52 var window = Window.GetWindow(selector);
57 var focusedElement = FocusManager.GetFocusedElement(window) as
DependencyObject;
58 if (focusedElement == null)
62 var element = selector.ItemContainerGenerator.ContainerFromIndex(selector.SelectedIndex);
64 if (!ReferenceEquals(focusedElement, selector) && !ReferenceEquals(focusedElement, element))
75 moved = AssociatedObject.Orientation == Orientation.Vertical ? MoveToNextItem() : MoveToNextLineItem(1);
79 moved = AssociatedObject.Orientation == Orientation.Vertical ? MoveToPreviousItem() : MoveToPreviousLineItem(1);
83 moved = AssociatedObject.Orientation == Orientation.Vertical ? MoveToPreviousLineItem(1) : MoveToPreviousItem();
87 moved = AssociatedObject.Orientation == Orientation.Vertical ? MoveToNextLineItem(1) : MoveToNextItem();
91 if (AssociatedObject.Orientation ==
Orientation.Vertical)
93 var itemHeight = AssociatedObject.ItemSlotSize.Height + AssociatedObject.MinimumItemSpacing * 2.0f;
94 moved = MoveToPreviousLineItem((
int)(AssociatedObject.ViewportHeight / itemHeight));
98 var itemWidth = AssociatedObject.ItemSlotSize.Width + AssociatedObject.MinimumItemSpacing * 2.0f;
99 moved = MoveToPreviousLineItem((
int)(AssociatedObject.ViewportWidth / itemWidth));
104 if (AssociatedObject.Orientation ==
Orientation.Vertical)
106 var itemHeight = AssociatedObject.ItemSlotSize.Height + AssociatedObject.MinimumItemSpacing * 2.0f;
107 moved = MoveToNextLineItem((
int)(AssociatedObject.ViewportHeight / itemHeight));
111 var itemWidth = AssociatedObject.ItemSlotSize.Width + AssociatedObject.MinimumItemSpacing * 2.0f;
112 moved = MoveToNextLineItem((
int)(AssociatedObject.ViewportWidth / itemWidth));
117 moved = selector.Items.MoveCurrentToFirst();
121 moved = selector.Items.MoveCurrentToLast();
132 if (selector.SelectedIndex > -1)
134 AssociatedObject.ScrollToIndexedItem(selector.SelectedIndex);
136 if (selector.ItemContainerGenerator != null && selector.SelectedItem != null)
138 var lbi = selector.ItemContainerGenerator.ContainerFromItem(selector.SelectedItem) as UIElement;
146 private bool MoveToPreviousLineItem(
int lineCount)
150 int newPos = selector.SelectedIndex - (AssociatedObject.ItemsPerLine * lineCount);
153 moved = selector.Items.MoveCurrentToPosition(newPos);
158 private bool MoveToNextLineItem(
int lineCount)
162 if (AssociatedObject.ItemCount > -1)
164 int newPos = selector.SelectedIndex + (AssociatedObject.ItemsPerLine * lineCount);
166 if (newPos < AssociatedObject.ItemCount)
167 moved = selector.Items.MoveCurrentToPosition(newPos);
172 private bool MoveToPreviousItem()
174 bool moved = selector.Items.MoveCurrentToPrevious();
177 if (selector.SelectedItem == null)
178 selector.Items.MoveCurrentToFirst();
183 private bool MoveToNextItem()
185 bool moved = selector.Items.MoveCurrentToNext();
188 if (selector.SelectedItem == null)
189 selector.Items.MoveCurrentToLast();
override void OnAttachedOverride()
override void OnDetachingOverride()
Android.Widget.Orientation Orientation