You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/components/dynamiccomponent.md
+5-7Lines changed: 5 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -143,8 +143,9 @@ In the following example, a Razor component renders a component based on the use
143
143
144
144
In the preceding example:
145
145
146
-
* Component names are used as the option values using the [`nameof` operator](/dotnet/csharp/language-reference/operators/nameof), which returns component names as constant strings.
147
-
* The namespace of the app is `BlazorSample`. ***Change the namespace to match your app's namespace.***
146
+
* An <xref:System.Collections.Generic.Dictionary%602> is used to manage components to be displayed.
147
+
* Names serve as the dictionary keys and are provided as selection options.
148
+
* Component types are stored as dictionary values using the [`typeof` operator](/dotnet/csharp/language-reference/operators/type-testing-and-cast#typeof-operator).
148
149
149
150
## Pass parameters
150
151
@@ -197,7 +198,7 @@ The following `RocketLabWithWindowSeat` component (`RocketLabWithWindowSeat.razo
197
198
In the following example:
198
199
199
200
* Only the `RocketLabWithWindowSeat` component's parameter for a window seat (`WindowSeat`) receives the value of the **`Window Seat`** checkbox.
200
-
*The namespace of the app is `BlazorSample`. ***Change the namespace to match your app's namespace.***
201
+
*Component names are used as dictionary keys using the [`nameof` operator](/dotnet/csharp/language-reference/operators/nameof), which returns component names as constant strings.
201
202
* The dynamically-rendered components are shared components:
202
203
* Shown in this article section: `RocketLabWithWindowSeat` (`RocketLabWithWindowSeat.razor`)
203
204
* Components shown in the [Example](#example) section earlier in this article:
@@ -340,10 +341,7 @@ In the following parent component example, the `ShowDTMessage` method assigns a
340
341
The parent component passes the callback method, `ShowDTMessage` in the parameter dictionary:
341
342
342
343
* The `string` key is the callback method's name, `OnClickCallback`.
343
-
* The `object` value is created by <xref:Microsoft.AspNetCore.Components.EventCallbackFactory.Create%2A?displayProperty=nameWithType> for the parent callback method, `ShowDTMessage`. Note that the [`this` keyword](/dotnet/csharp/language-reference/keywords/this) isn't supported in C# fields, so a C# property is used for the parameter dictionary.
344
-
345
-
> [!IMPORTANT]
346
-
> For the following component, modify the code in the `OnDropdownChange` method. Change the namespace name of "`BlazorSample`" in the `Type.GetType()` argument to match your app's namespace.
344
+
* The `object` value is created by <xref:Microsoft.AspNetCore.Components.EventCallbackFactory.Create%2A?displayProperty=nameWithType> for the parent callback method, `ShowDTMessage`. Note that the [`this` keyword](/dotnet/csharp/language-reference/keywords/this) isn't supported in C# field initialization, so a C# property is used for the parameter dictionary.
* The component's [`ShouldRender` method](#suppress-ui-refreshing-shouldrender) returns `false`.
36
+
* The override of the component's [`ShouldRender` method](#suppress-ui-refreshing-shouldrender) returns `false` (the default `ComponentBase` implementation always returns `true`).
37
37
38
38
## Control the rendering flow
39
39
@@ -256,9 +256,9 @@ One way to deal with this scenario is to provide a *state management* class, oft
256
256
257
257
For approaches to manage state, see the following resources:
258
258
259
-
*[Server-side in-memory state container service](xref:blazor/state-management?pivots=server#in-memory-state-container-service-server) ([client-side equivalent](xref:blazor/state-management?pivots=webassembly#in-memory-state-container-service-wasm)) section of the *State management* article.
260
-
*[Pass data across a component hierarchy](xref:blazor/components/cascading-values-and-parameters#pass-data-across-a-component-hierarchy) using cascading values and parameters.
261
259
*[Bind across more than two components](xref:blazor/components/data-binding#bind-across-more-than-two-components) using data bindings.
260
+
*[Pass data across a component hierarchy](xref:blazor/components/cascading-values-and-parameters#pass-data-across-a-component-hierarchy) using cascading values and parameters.
261
+
*[Server-side in-memory state container service](xref:blazor/state-management?pivots=server#in-memory-state-container-service-server) ([client-side equivalent](xref:blazor/state-management?pivots=webassembly#in-memory-state-container-service-wasm)) section of the *State management* article.
262
262
263
263
For the state manager approach, C# events are outside the Blazor rendering pipeline. Call <xref:Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged%2A> on other components you wish to rerender in response to the state manager's events.
Copy file name to clipboardExpand all lines: aspnetcore/blazor/components/virtualization.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,8 @@ If the collection contains thousands of flights, rendering the flights takes a l
46
46
Instead of rendering the entire list of flights at once, replace the [`foreach`](/dotnet/csharp/language-reference/keywords/foreach-in) loop in the preceding example with the <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601> component:
47
47
48
48
* Specify `allFlights` as a fixed item source to <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601.Items%2A?displayProperty=nameWithType>. Only the currently visible flights are rendered by the <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601> component.
49
+
50
+
If a non-generic collection supplies the items, for example a collection of <xref:System.Data.DataRow>, follow the guidance in the [Item provider delegate](#item-provider-delegate) section to supply the items.
49
51
* Specify a context for each flight with the `Context` parameter. In the following example, `flight` is used as the context, which provides access to each flight's members.
50
52
51
53
```razor
@@ -70,8 +72,7 @@ The <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601> com
70
72
71
73
* Calculates the number of items to render based on the height of the container and the size of the rendered items.
72
74
* Recalculates and rerenders the items as the user scrolls.
73
-
* Only fetches the slice of records from an external API that correspond to the current visible region, instead of downloading all of the data from the collection.
74
-
* Receives a generic <xref:System.Collections.Generic.ICollection%601> for <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601.Items?displayProperty=nameWithType>. If a non-generic collection supplies the items (for example, a collection of <xref:System.Data.DataRow>), follow the guidance in the [Item provider delegate](#item-provider-delegate) section to supply the items.
75
+
* Only fetches the slice of records from an external API that correspond to the currently visible region, including overscan, when `ItemsProvider` is used instead of `Items` (see the [Item provider delegate](#item-provider-delegate) section).
75
76
76
77
The item content for the <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601> component can include:
Copy file name to clipboardExpand all lines: aspnetcore/blazor/fundamentals/routing.md
+65Lines changed: 65 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1609,6 +1609,71 @@ The following HTML markup is rendered:
1609
1609
> }
1610
1610
> ```
1611
1611
1612
+
<xref:Microsoft.AspNetCore.Components.Routing.NavLink> component entries can be dynamically created from the app's components via reflection. The following example demonstrates the general approach for further customization.
1613
+
1614
+
For the following demonstration, a consistent, standard naming convention is used for the app's components:
1615
+
1616
+
* Routable component file names use Pascal case†, for example `Pages/ProductDetail.razor`.
1617
+
* Routable component file paths match their URLs in kebab case‡ with hyphens appearing between words in a component's route template. For example, a `ProductDetail` component with a route template of `/product-detail` (`@page "/product-detail"`) is requested in a browser at the relative URL `/product-detail`.
1618
+
1619
+
†Pascal case (upper camel case) is a naming convention without spaces and punctuation and with the first letter of each word capitalized, including the first word.
1620
+
‡Kebab case is a naming convention without spaces and punctuation that uses lowercase letters and dashes between words.
1621
+
1622
+
In the Razor markup of the `NavMenu` component (`NavMenu.razor`) under the default `Home` page, <xref:Microsoft.AspNetCore.Components.Routing.NavLink> components are added from a collection:
The `GetRoutableComponents` method in the `@code` block:
1650
+
1651
+
```csharp
1652
+
publicIEnumerable<string>GetRoutableComponents()
1653
+
{
1654
+
returnAssembly.GetExecutingAssembly()
1655
+
.ExportedTypes
1656
+
.Where(t=>t.IsSubclassOf(typeof(ComponentBase)))
1657
+
.Where(c=>c.GetCustomAttributes(inherit: true)
1658
+
.OfType<RouteAttribute>()
1659
+
.Any())
1660
+
.Where(c=>c.Name!="Home"&&c.Name!="Error")
1661
+
.OrderBy(o=>o.Name)
1662
+
.Select(c=>c.Name);
1663
+
}
1664
+
```
1665
+
1666
+
The preceding example doesn't include the following pages in the rendered list of components:
1667
+
1668
+
*`Home` page: The page is listed separately from the automatically generated links because it should appear at the top of the list and set the `Match` parameter.
1669
+
*`Error` page: The error page is only navigated to by the framework and shouldn't be listed.
1670
+
1671
+
:::moniker range=">= aspnetcore-8.0"
1672
+
1673
+
For an example of the preceding code in a sample app that you can run locally, obtain the [**Blazor Web App** or **Blazor WebAssembly** sample app](xref:blazor/fundamentals/index#sample-apps).
0 commit comments