|
|
|
@ -79,15 +79,15 @@ public partial class MainPage : ContentPage, INotifyPropertyChanged
|
|
|
|
private void InitializeCollectionViews()
|
|
|
|
private void InitializeCollectionViews()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LeftPanel.ItemTemplate = PanelCollectionView.CreateItemTemplate(isLeftPanel: true, page: this);
|
|
|
|
LeftPanel.ItemTemplate = PanelCollectionView.CreateItemTemplate(isLeftPanel: true, page: this);
|
|
|
|
RightPanel.ItemTemplate = PanelCollectionView.CreateItemTemplate(isLeftPanel: true, page: this);
|
|
|
|
RightPanel.ItemTemplate = PanelCollectionView.CreateItemTemplate(isLeftPanel: false, page: this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnHandlerChanged()
|
|
|
|
//protected override void OnHandlerChanged()
|
|
|
|
{
|
|
|
|
//{
|
|
|
|
base.OnHandlerChanged();
|
|
|
|
// base.OnHandlerChanged();
|
|
|
|
this.Focus();
|
|
|
|
// this.Focus();
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
public void HandleItemClick(FileSystemItem item, bool isLeftPanel)
|
|
|
|
public void HandleItemClick(FileSystemItem item, bool isLeftPanel)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -150,13 +150,13 @@ public partial class MainPage : ContentPage, INotifyPropertyChanged
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Переключаем фокус с указанием направления
|
|
|
|
// Переключаем фокус с указанием направления
|
|
|
|
private void MoveFocus(bool moveForward = true)
|
|
|
|
private void MoveFocus(bool moveForward, bool isLeft)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var allFocusable = GetFocusableElements();
|
|
|
|
var allFocusable = GetFocusableElements(isLeft);
|
|
|
|
var current = allFocusable.FirstOrDefault(x => x.IsFocused);
|
|
|
|
var current = allFocusable.FirstOrDefault(x => x.IsFocused);
|
|
|
|
var next = moveForward ?
|
|
|
|
var next = moveForward ?
|
|
|
|
GetNextFocusable(current, allFocusable) :
|
|
|
|
GetNextFocusable(current, allFocusable) :
|
|
|
|
GetPreviousFocusable(current, allFocusable);
|
|
|
|
GetPreviousFocusable(current, allFocusable);
|
|
|
|
|
|
|
|
|
|
|
|
next?.Focus();
|
|
|
|
next?.Focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -185,13 +185,30 @@ public partial class MainPage : ContentPage, INotifyPropertyChanged
|
|
|
|
return allElements[prevIndex];
|
|
|
|
return allElements[prevIndex];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<View> GetFocusableElements()
|
|
|
|
private List<View> GetFocusableElements(bool isLeft)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return this.GetVisualTreeDescendants()
|
|
|
|
List<View>? elements = null;
|
|
|
|
.OfType<View>()
|
|
|
|
if (isLeft)
|
|
|
|
.Where(x => x.IsEnabled && x.IsVisible)
|
|
|
|
{
|
|
|
|
|
|
|
|
elements = LeftPanel.GetVisualTreeDescendants().OfType<View>()
|
|
|
|
|
|
|
|
.Where(x => x.IsEnabled && x.IsVisible && x is Button)
|
|
|
|
|
|
|
|
.OrderBy(GetVisualTreeOrder) // Сортируем по порядку в визуальном дереве
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
elements = RightPanel.GetVisualTreeDescendants().OfType<View>()
|
|
|
|
|
|
|
|
.Where(x => x.IsEnabled && x.IsVisible && x is Button)
|
|
|
|
.OrderBy(GetVisualTreeOrder) // Сортируем по порядку в визуальном дереве
|
|
|
|
.OrderBy(GetVisualTreeOrder) // Сортируем по порядку в визуальном дереве
|
|
|
|
.ToList();
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//foreach (var el in elements)
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// System.Diagnostics.Debug.WriteLine($"!!! {el.ToString()}");
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return elements;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int GetVisualTreeOrder(View view)
|
|
|
|
private int GetVisualTreeOrder(View view)
|
|
|
|
@ -214,19 +231,19 @@ public partial class MainPage : ContentPage, INotifyPropertyChanged
|
|
|
|
_leftSelectedIndex = LeftItems.IndexOf(selectedItem);
|
|
|
|
_leftSelectedIndex = LeftItems.IndexOf(selectedItem);
|
|
|
|
_isLeftPanelActive = true;
|
|
|
|
_isLeftPanelActive = true;
|
|
|
|
|
|
|
|
|
|
|
|
System.Diagnostics.Debug.WriteLine($"L !!! {_leftSelectedIndex} {_lastLeftSelectedIndex}");
|
|
|
|
// System.Diagnostics.Debug.WriteLine($"L !!! {_leftSelectedIndex} {_lastLeftSelectedIndex}");
|
|
|
|
if (_lastLeftSelectedIndex < LeftItems.Count && _lastLeftSelectedIndex >= 0)
|
|
|
|
if (_lastLeftSelectedIndex < LeftItems.Count && _lastLeftSelectedIndex >= 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Автоматически переключаем фокус при достижении границ
|
|
|
|
// Автоматически переключаем фокус при достижении границ
|
|
|
|
if (_leftSelectedIndex > _lastLeftSelectedIndex)
|
|
|
|
if (_leftSelectedIndex > _lastLeftSelectedIndex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Достигли конца списка - переходим к следующему элементу
|
|
|
|
// Достигли конца списка - переходим к следующему элементу
|
|
|
|
MoveFocus(moveForward: true);
|
|
|
|
MoveFocus(moveForward: true, isLeft: true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (_leftSelectedIndex < _lastLeftSelectedIndex)
|
|
|
|
else if (_leftSelectedIndex < _lastLeftSelectedIndex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Достигли начала списка - переходим к предыдущему элементу
|
|
|
|
// Достигли начала списка - переходим к предыдущему элементу
|
|
|
|
MoveFocus(moveForward: false);
|
|
|
|
MoveFocus(moveForward: false, isLeft: true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -241,23 +258,23 @@ public partial class MainPage : ContentPage, INotifyPropertyChanged
|
|
|
|
_rightSelectedIndex = RightItems.IndexOf(selectedItem);
|
|
|
|
_rightSelectedIndex = RightItems.IndexOf(selectedItem);
|
|
|
|
_isLeftPanelActive = false;
|
|
|
|
_isLeftPanelActive = false;
|
|
|
|
|
|
|
|
|
|
|
|
System.Diagnostics.Debug.WriteLine($"R !!! {_rightSelectedIndex} {_lastRightSelectedIndex}");
|
|
|
|
// System.Diagnostics.Debug.WriteLine($"R !!! {_rightSelectedIndex} {_lastRightSelectedIndex}");
|
|
|
|
if (_lastRightSelectedIndex < RightItems.Count && _lastRightSelectedIndex >= 0)
|
|
|
|
if (_lastRightSelectedIndex < RightItems.Count && _lastRightSelectedIndex >= 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Автоматически переключаем фокус при достижении границ
|
|
|
|
// Автоматически переключаем фокус при достижении границ
|
|
|
|
if (_rightSelectedIndex > _lastRightSelectedIndex)
|
|
|
|
if (_rightSelectedIndex > _lastRightSelectedIndex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Достигли конца списка - переходим к следующему элементу
|
|
|
|
// Достигли конца списка - переходим к следующему элементу
|
|
|
|
MoveFocus(moveForward: true);
|
|
|
|
MoveFocus(moveForward: true, isLeft: false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (_rightSelectedIndex < _lastRightSelectedIndex)
|
|
|
|
else if (_rightSelectedIndex < _lastRightSelectedIndex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Достигли начала списка - переходим к предыдущему элементу
|
|
|
|
// Достигли начала списка - переходим к предыдущему элементу
|
|
|
|
MoveFocus(moveForward: false);
|
|
|
|
MoveFocus(moveForward: false, isLeft: false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UpdateVisualSelection();
|
|
|
|
UpdateVisualSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|