Проблемы в настройке Xamarin.Forms.ListView
Задача: Мне нужно реализовать контрол для отображения элементов в GridView как на андроиде.
Суть проблемы и попытка ее реализации: Создаю класс GridListBox унаследованный от GridListBox Xamarin.Forms.ListView. В следующий раз я создал GridListBoxRenderer, например, Xamarin.Forms.Platform.Android.ListViewRenderer.
Мой GridListBox:
public class GridListBox : ListView
{
public static readonly BindableProperty ColumnCountProperty = BindableProperty.Create<GridListBox, int>(r => r.ColumnCount, 2);
public int ColumnCount
{
get { return (int)GetValue(ColumnCountProperty); }
set { SetValue(ColumnCountProperty, value); }
}
public static readonly BindableProperty HorizontalSpacingProperty = BindableProperty.Create<GridListBox, int>(r => r.HorizontalSpacing, 5);
public int HorizontalSpacing
{
get { return (int)GetValue(HorizontalSpacingProperty); }
set { SetValue(HorizontalSpacingProperty, value); }
}
public static readonly BindableProperty VerticalSpacingProperty = BindableProperty.Create<GridListBox, int>(r => r.VerticalSpacing, 5);
public int VerticalSpacing
{
get { return (int)GetValue(VerticalSpacingProperty); }
set { SetValue(VerticalSpacingProperty, value); }
}
}
Рендерер для GridListBox:
public class GridListBoxRenderer:NativeRenderer
{
private Cell cellFocused;
protected override void OnModelChanged(VisualElement oldModel, VisualElement newModel)
{
base.OnModelChanged(oldModel, newModel);
var realListView = (GridView)Control;
if (realListView == null)
{
realListView = new GridView(Context);
SetNativeControl((View)realListView);
}
cellFocused = (Cell)null;
realListView.Focusable = false;
realListView.DescendantFocusability = DescendantFocusability.AfterDescendants;
realListView.OnFocusChangeListener = (IOnFocusChangeListener)this;
realListView.SetNumColumns(((Controls.GridListBox) newModel).ColumnCount);
realListView.SetHorizontalSpacing(((Controls.GridListBox)newModel).HorizontalSpacing);
realListView.SetVerticalSpacing(((Controls.GridListBox)newModel).VerticalSpacing);
realListView.Adapter = new GridViewAdapter(Context, realListView, (Controls.GridListBox)newModel);
}
public override Size MinimumSize()
{
return new Size(40.0, 40.0);
}
}
И тут началось самое интересное: реализация GridViewAdapter проста, если взять, например, Xamarin.Forms.Platform.Android.ListViewAdapter (доступ как Internal). Для реализации общедоступного BaseAdapter.GetView (int position, View convertView, ViewGroup parent) с использованием ItemTemplate требуется доступ к Xamarin.Forms.ListView.TemplatedItems, но он является внутренним...
P.S. Как разработчики из Xamarin планировали дать возможность разработчикам настраивать Xamarin.Forms, если большинство свойств с внутренним доступом...?
П.П.С. Аналогичные трудности возникают при настройке Xamarin.Forms.Page. Свойство Xamarin.Forms.Page.InternalChildren является внутренним