/// hahaha
/// </summary>
public partial class AppItemCell : ViewCell
- {
- public static readonly BindableProperty OnClickedCommandProperty = BindableProperty.Create("OnClickedCommand", typeof(ICommand), typeof(AppItemCell), default(ICommand));
- public ICommand OnClickedCommand
- {
- get { return (ICommand)GetValue(OnClickedCommandProperty); }
- set { SetValue(OnClickedCommandProperty, value); }
- }
+ {
+ public ICommand OnClickedCommand { get; set; }
+
+ public ICommand OnFocusedCommand { get; set; }
public static readonly BindableProperty IsPinnedProperty = BindableProperty.Create("IsPinned", typeof(bool), typeof(AppItemCell), default(bool));
public bool IsPinned
private void OnClicked(object sender, EventArgs e)
{
- OnClickedCommand.Execute("");
+ OnClickedCommand?.Execute("");
}
private void OnFocused(object sender, EventArgs e)
{
+ OnFocusedCommand?.Execute("");
ButtonImage.ScaleTo(1.32, 300);
ButtonImage.TranslateTo(0.0, 2.0, 300);
TextArea.TranslateTo(0.0, 26.0, 300);
Orientation="Horizontal">
<Grid x:Name="AppListGrid"
HorizontalOptions="Start"
- Padding="58,0,0,0">
+ Padding="58,0,58,0">
<Grid.RowDefinitions>
<RowDefinition Height="133*" />
<RowDefinition Height="8*" />
using LibTVRefCommmonPortable.DataModels;
using LibTVRefCommmonPortable.Utils;
using System.Collections.Generic;
+using System;
+using System.Threading.Tasks;
namespace TVApps.Controls
{
return;
}
+ // For Test Code
+ //for (var test = 0; test < 4; test++)
+ //{
foreach (var item in ItemsSource)
{
var viewCell = ItemTemplate.CreateContent() as AppItemCell;
{
item.DoAction();
});
+ var index = AppCount / 2;
+ viewCell.OnFocusedCommand = new Command(() =>
+ {
+ ScrollToIndex(index);
+ });
if (AppCount % 2 == 0)
{
AppUpperList.Children.Add(viewCell.View);
AppCount = AppCount + 1;
}
+ //}
+
+ InitializeFocus();
+ }
- FocusInitialize();
+ private async void ScrollToIndex(int index)
+ {
+ var StartX = AppUpperList.Children[index].X;
+ var LowerBound = StartX - 16 - 57 - (256 * 6) + 58;
+ LowerBound = LowerBound > 0 ? LowerBound : 0;
+ var UpperBound = StartX - 16 - 57 + 58;
+ UpperBound = UpperBound > 0 ? UpperBound : 0;
+
+ // Is Focusable.
+ if (ScrollX >= LowerBound && ScrollX <= UpperBound)
+ {
+ return;
+ }
+
+ var Ldiff = Math.Abs(ScrollX - LowerBound);
+ var Rdiff = Math.Abs(ScrollX - UpperBound);
+
+ if (Ldiff > Rdiff)
+ {
+ await Task.Delay(1);
+ await ScrollToAsync(UpperBound, 0, true);
+ }
+ else
+ {
+ await Task.Delay(1);
+ await ScrollToAsync(LowerBound, 0, true);
+ }
}
- public void FocusInitialize()
+ public void InitializeFocus()
{
if (AppUpperList.Children.Count > 0)
{
break;
}
- AppList.FocusInitialize();
+ AppList.InitializeFocus();
}
private void MainPage_PropertyChanged(object sender, PropertyChangedEventArgs e)