Skip to content

Commit 1b4ca8a

Browse files
authored
Merge pull request #37140 from dotnet/main
Merge to Live
2 parents 11860bd + c3ce885 commit 1b4ca8a

16 files changed

Lines changed: 634 additions & 35 deletions

aspnetcore/blazor/components/virtualization.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,59 @@ The <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601> com
274274

275275
:::moniker-end
276276

277+
:::moniker range=">= aspnetcore-11.0"
278+
279+
## Control viewport scroll position behavior when items are dynamically added
280+
281+
<!-- UPDATE 11.0 - API cross-links -->
282+
283+
Assign a `VirtualizeAnchorMode` value to the `AnchorMode` parameter to control how the viewport behaves at list edges when items are dynamically added:
284+
285+
* `None`: No edge pinning. The viewport stays at the current scroll position regardless of item changes.
286+
* `Beginning`: Pins the viewport to the beginning of the list. When the user is at a scroll position near the top of the list and new items arrive at the beginning, the viewport stays at the top showing the newest items. For example, this pinning behavior is useful for a news feed user experience.
287+
* `End`: Pins the viewport to the end of the list. When the user is at a scroll position near the bottom of the list and new items arrive at the end, the viewport auto-scrolls to show them. If the user has scrolled away, auto-scroll disengages until they return to the bottom. For example, this pinning behavior is useful for a chat or logging user experience.
288+
289+
The following example pins the viewport to the beginning of a virtualized flight list:
290+
291+
```razor
292+
<div style="height:500px;overflow-y:scroll">
293+
<Virtualize Items="allFlights" Context="flight" AnchorMode="Beginning">
294+
<FlightSummary @key="flight.FlightId" Details="@flight.Summary" />
295+
</Virtualize>
296+
</div>
297+
```
298+
299+
Modes can be combined. For example, assigning `Beginning | End` pins both edges. Combining `None` with other modes is supported but doesn't change the combined value.
300+
301+
`Virtualize.ItemComparer` gets or sets a comparer used to detect whether items were prepended or appended when using class-typed items with an <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601.ItemsProvider%2A> (for more information, see the [Item provider delegate](#item-provider-delegate) section).
302+
303+
The comparer determines if the first loaded item changed between provider calls, which indicates items were inserted at the top. For records, the default comparer's value-equality behavior (`EqualityComparer<T>.Default`) works automatically. For an in-memory <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601.Items%2A> assignment, an `ItemComparer` comparer isn't required because the component can detect prepends automatically. In cases where non-primative objects are virtualized and the framework can't detect if an item is prepended or appended, assign an <xref:System.Collections.Generic.IEqualityComparer%601> to the `Virtualize` component:
304+
305+
<!-- UPDATE 11.0 - Ilona ... Does the 'itemComparer' in the following example
306+
need the '@' symbol (ItemComparer="@itemComparer")?
307+
I thought that it wouldn't need it. -->
308+
309+
```razor
310+
<Virtualize ItemsProvider="LoadFlights" AnchorMode="Beginning"
311+
ItemComparer="itemComparer">
312+
...
313+
</Virtualize>
314+
315+
@code {
316+
private static readonly IEqualityComparer<Flight> itemComparer =
317+
EqualityComparer<Flight>.Create((a, b) =>
318+
a.Index == b.Index, item => item.Index);
319+
320+
private async ValueTask<ItemsProviderResult<Flight>> LoadFlights(
321+
ItemsProviderRequest request)
322+
{
323+
...
324+
}
325+
}
326+
```
327+
328+
:::moniker-end
329+
277330
## State changes
278331

279332
When making changes to items rendered by the <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601> component, call <xref:Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged%2A> to enqueue re-evaluation and rerendering of the component. For more information, see <xref:blazor/components/rendering>.

aspnetcore/blazor/debug.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,27 @@ Blazor Server: [`Microsoft.AspNetCore.Components.WebAssembly.Server`](https://ww
164164

165165
:::moniker-end
166166

167-
Standalone Blazor WebAssembly: [`Microsoft.AspNetCore.Components.WebAssembly.DevServer`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.DevServer): Development server for use when building Blazor apps. Calls <xref:Microsoft.AspNetCore.Builder.WebAssemblyNetDebugProxyAppBuilderExtensions.UseWebAssemblyDebugging%2A> internally to add middleware for debugging Blazor WebAssembly apps inside Chromium developer tools.
167+
<!-- UPDATE 11.0 - Activate when the NuGet package is available.
168+
169+
https://www.nuget.org/packages?q=Microsoft.AspNetCore.Components.Gateway
170+
171+
:::moniker range=">= aspnetcore-11.0"
172+
173+
Standalone Blazor WebAssembly: [`Microsoft.AspNetCore.Components.Gateway`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.Gateway): A lightweight ASP.NET Core host for serving standalone Blazor WebAssembly apps during development and production.
174+
175+
:::moniker-end
176+
177+
:::moniker range="< aspnetcore-11.0"
178+
179+
-->
180+
181+
Standalone Blazor WebAssembly: [`Microsoft.AspNetCore.Components.WebAssembly.DevServer`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.DevServer): Development server for use when building Blazor WebAssembly apps. Calls <xref:Microsoft.AspNetCore.Builder.WebAssemblyNetDebugProxyAppBuilderExtensions.UseWebAssemblyDebugging%2A> internally to add middleware for debugging Blazor WebAssembly apps inside Chromium developer tools.
182+
183+
<!-- UPDATE 11.0 - Activate when the NuGet package is available.
184+
185+
:::moniker-end
186+
187+
-->
168188

169189
:::moniker range="< aspnetcore-8.0"
170190

aspnetcore/blazor/security/webassembly/standalone-with-identity/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,34 @@ A standalone Blazor WebAssembly frontend app demonstrates user authentication an
181181

182182
The app uses the following NuGet packages:
183183

184+
<!-- UPDATE 11.0 - Activate when the NuGet package is available.
185+
186+
https://www.nuget.org/packages?q=Microsoft.AspNetCore.Components.Gateway
187+
188+
:::moniker range=">= aspnetcore-11.0"
189+
190+
* [`Microsoft.AspNetCore.Components.WebAssembly.Authentication`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.Authentication)
191+
* [`Microsoft.Extensions.Http`](https://www.nuget.org/packages/Microsoft.Extensions.Http)
192+
* [`Microsoft.AspNetCore.Components.WebAssembly`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly)
193+
* [`Microsoft.AspNetCore.Components.Gateway`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.Gateway)
194+
195+
:::moniker-end
196+
197+
:::moniker range="< aspnetcore-11.0"
198+
199+
-->
200+
184201
* [`Microsoft.AspNetCore.Components.WebAssembly.Authentication`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.Authentication)
185202
* [`Microsoft.Extensions.Http`](https://www.nuget.org/packages/Microsoft.Extensions.Http)
186203
* [`Microsoft.AspNetCore.Components.WebAssembly`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly)
187204
* [`Microsoft.AspNetCore.Components.WebAssembly.DevServer`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.DevServer)
188205

206+
<!-- UPDATE 11.0 - Activate when the NuGet package is available.
207+
208+
:::moniker-end
209+
210+
-->
211+
189212
### Sample app code
190213

191214
The `Models` folder contains the app's models:

0 commit comments

Comments
 (0)