Add a workaround for collection view bug.

This commit is contained in:
Oleksandr Liakhevych 2022-03-18 09:42:36 +02:00
Родитель 606a668669
Коммит 2ed9361d40
4 изменённых файлов: 17 добавлений и 14 удалений

Просмотреть файл

@ -12,13 +12,13 @@ namespace Microsoft.MobileBlazorBindings.Elements.DataTemplates
internal class DataTemplateItemComponent<T> : ComponentBase
#pragma warning restore CA1812 // Avoid uninstantiated internal classes
{
private MC.ContentView _contentView;
private MC.VerticalStackLayout _contentView;
private object _item;
[Parameter] public RenderFragment<T> Template { get; set; }
[Parameter]
public MC.ContentView ContentView
public MC.VerticalStackLayout ContentView
{
get
{

Просмотреть файл

@ -18,9 +18,9 @@ namespace Microsoft.MobileBlazorBindings.Elements.DataTemplates
foreach (var itemRoot in _itemRoots)
{
builder.OpenComponent<InitializedContentView>(1);
builder.OpenComponent<InitializedVerticalStackLayout>(1);
builder.AddAttribute(2, nameof(InitializedContentView.NativeControl), itemRoot);
builder.AddAttribute(2, nameof(InitializedVerticalStackLayout.NativeControl), itemRoot);
builder.AddAttribute(3, "ChildContent", (RenderFragment)(builder =>
{
builder.OpenComponent<DataTemplateItemComponent<T>>(4);
@ -39,9 +39,9 @@ namespace Microsoft.MobileBlazorBindings.Elements.DataTemplates
[Parameter] public string ElementName { get; set; }
[Parameter] public RenderFragment<T> Template { get; set; }
private readonly List<MC.ContentView> _itemRoots = new List<MC.ContentView>();
private readonly List<MC.VerticalStackLayout> _itemRoots = new();
public void Add(MC.ContentView templateRoot)
public void Add(MC.VerticalStackLayout templateRoot)
{
_itemRoots.Add(templateRoot);
StateHasChanged();

Просмотреть файл

@ -9,15 +9,18 @@ using MC = Microsoft.Maui.Controls;
namespace Microsoft.MobileBlazorBindings.Elements.DataTemplates
{
#pragma warning disable CA1812 // Avoid uninstantiated internal classes. Class is used as generic parameter.
internal class InitializedContentView : ContentView
internal class InitializedVerticalStackLayout : VerticalStackLayout
#pragma warning restore CA1812 // Avoid uninstantiated internal classes
{
[Parameter] public new MC.ContentView NativeControl { get; set; }
// ContentView was originally used here.
// It was replaced with VerticalStackLayout as a workaround for bug
// https://github.com/dotnet/maui/issues/5248.
[Parameter] public new MC.VerticalStackLayout NativeControl { get; set; }
static InitializedContentView()
static InitializedVerticalStackLayout()
{
ElementHandlerRegistry.RegisterElementHandler<InitializedContentView>(
(renderer, _, component) => new ContentViewHandler(renderer, component.NativeControl));
ElementHandlerRegistry.RegisterElementHandler<InitializedVerticalStackLayout>(
(renderer, _, component) => new VerticalStackLayoutHandler(renderer, component.NativeControl));
}
}
}

Просмотреть файл

@ -10,9 +10,9 @@ namespace Microsoft.MobileBlazorBindings.Elements.DataTemplates
public MbbDataTemplate(DataTemplateItemsComponent<T> dataTemplateItemsAccessor)
: base(() =>
{
var contentView = new MC.ContentView();
dataTemplateItemsAccessor.Add(contentView);
return contentView;
var itemRootView = new MC.VerticalStackLayout();
dataTemplateItemsAccessor.Add(itemRootView);
return itemRootView;
})
{
}