Beispiel #1
0
        /// <inheritdoc />
        protected override void OnParametersSet()
        {
            if (ItemSize <= 0)
            {
                throw new InvalidOperationException(
                          $"{GetType()} requires a positive value for parameter '{nameof(ItemSize)}' to perform virtualization.");
            }

            if (ItemsProvider != null)
            {
                if (Items != null)
                {
                    throw new InvalidOperationException(
                              $"{GetType()} can only accept one item source from its parameters. " +
                              $"Do not supply both '{nameof(Items)}' and '{nameof(ItemsProvider)}'.");
                }

                _itemsProvider = ItemsProvider;
            }
            else if (Items != null)
            {
                _itemsProvider = DefaultItemsProvider;
            }
            else
            {
                throw new InvalidOperationException(
                          $"{GetType()} requires either the '{nameof(Items)}' or '{nameof(ItemsProvider)}' parameters to be specified " +
                          $"and non-null.");
            }

            _itemTemplate = ItemContent ?? ChildContent;
            _placeholder  = Placeholder ?? DefaultPlaceholder;
        }
Beispiel #2
0
        /// <inheritdoc />
        protected override void OnParametersSet()
        {
            if (ItemSize <= 0)
            {
                throw new InvalidOperationException(
                          $"{GetType()} requires a positive value for parameter '{nameof(ItemSize)}'.");
            }

            if (_itemSize <= 0)
            {
                _itemSize = ItemSize;
            }

            if (ItemsProvider != null)
            {
                if (ItemsSource != null)
                {
                    throw new InvalidOperationException(
                              $"{GetType()} can only accept one item source from its parameters. " +
                              $"Do not supply both '{nameof(ItemsSource)}' and '{nameof(ItemsProvider)}'.");
                }

                _itemsProvider = ItemsProvider;
            }
            else if (ItemsSource != null)
            {
                _itemsProvider = DefaultItemsProvider;

                // When we have a fixed set of in-memory data, it doesn't cost anything to
                // re-query it on each cycle, so do that. This means the developer can add/remove
                // items in the collection and see the UI update without having to call RefreshDataAsync.
                ValueTask refreshTask = RefreshDataCoreAsync(renderOnSuccess: false);

                // We know it's synchronous and has its own error handling
                Debug.Assert(refreshTask.IsCompletedSuccessfully);
            }
            else
            {
                throw new InvalidOperationException(
                          $"{GetType()} requires either the '{nameof(ItemsSource)}' or '{nameof(ItemsProvider)}' parameters to be specified " +
                          $"and non-null.");
            }

            _itemTemplate = ItemTemplate ?? ChildContent;
            _placeholder  = Placeholder ?? DefaultPlaceholder;
        }
Beispiel #3
0
    private RenderFragment BuildVirtualize <TItem>(
        float itemSize,
        ItemsProviderDelegate <TItem> itemsProvider,
        ICollection <TItem> items,
        Action <Virtualize <TItem> > captureRenderedVirtualize = null)
    => builder =>
    {
        builder.OpenComponent <Virtualize <TItem> >(0);
        builder.AddAttribute(1, "ItemSize", itemSize);
        builder.AddAttribute(2, "ItemsProvider", itemsProvider);
        builder.AddAttribute(3, "Items", items);

        if (captureRenderedVirtualize != null)
        {
            builder.AddComponentReferenceCapture(4, component => captureRenderedVirtualize(component as Virtualize <TItem>));
        }

        builder.CloseComponent();
    };