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
@@ -414,23 +414,23 @@ In the following example, `UpdateHeading` is called asynchronously when the butt
414
414
415
415
For some events, event argument types are permitted. If access to one of these event types isn't necessary, it isn't required in the method call.
416
416
417
-
Supported [UIEventArgs](https://github.com/aspnet/AspNetCore/blob/release/3.0-preview8/src/Components/Components/src/UIEventArgs.cs) are shown in the following table.
417
+
Supported [EventArgs](https://github.com/aspnet/AspNetCore/tree/release/3.0-preview9/src/Components/Web/src/Web) are shown in the following table.
418
418
419
419
| Event | Class |
420
420
| ----- | ----- |
421
-
| Clipboard |`UIClipboardEventArgs`|
422
-
| Drag |`UIDragEventArgs`–`DataTransfer` is used to hold the dragged data during a drag and drop operation and may hold one or more `UIDataTransferItem`. `UIDataTransferItem` represents one drag data item. |
423
-
| Error |`UIErrorEventArgs`|
424
-
| Focus |`UIFocusEventArgs`– Doesn't include support for `relatedTarget`. |
425
-
|`<input>` change |`UIChangeEventArgs`|
426
-
| Keyboard |`UIKeyboardEventArgs`|
427
-
| Mouse |`UIMouseEventArgs`|
428
-
| Mouse pointer |`UIPointerEventArgs`|
429
-
| Mouse wheel |`UIWheelEventArgs`|
430
-
| Progress |`UIProgressEventArgs`|
431
-
| Touch |`UITouchEventArgs`–`UITouchPoint` represents a single contact point on a touch-sensitive device. |
432
-
433
-
For information on the properties and event handling behavior of the events in the preceding table, see [EventArgs classes in the reference source (aspnet/AspNetCore release/3.0-preview9 branch)](https://github.com/aspnet/AspNetCore/tree/release/3.0-preview9/src/Components/Web/src).
421
+
| Clipboard |`ClipboardEventArgs`|
422
+
| Drag |`DragEventArgs`–`DataTransfer`and `DataTransferItem` hold dragged item data. |
423
+
| Error |`ErrorEventArgs`|
424
+
| Focus |`FocusEventArgs`– Doesn't include support for `relatedTarget`. |
425
+
|`<input>` change |`ChangeEventArgs`|
426
+
| Keyboard |`KeyboardEventArgs`|
427
+
| Mouse |`MouseEventArgs`|
428
+
| Mouse pointer |`PointerEventArgs`|
429
+
| Mouse wheel |`WheelEventArgs`|
430
+
| Progress |`ProgressEventArgs`|
431
+
| Touch |`TouchEventArgs`–`TouchPoint` represents a single contact point on a touch-sensitive device. |
432
+
433
+
For information on the properties and event handling behavior of the events in the preceding table, see [EventArgs classes in the reference source (aspnet/AspNetCore release/3.0-preview9 branch)](https://github.com/aspnet/AspNetCore/tree/release/3.0-preview9/src/Components/Web/src/Web).
434
434
435
435
### Lambda expressions
436
436
@@ -517,10 +517,9 @@ Component references provide a way to reference a component instance so that you
517
517
518
518
* Add an [@ref](xref:mvc/views/razor#ref) attribute to the child component.
519
519
* Define a field with the same type as the child component.
520
-
* Provide the `@ref:suppressField` parameter, which suppresses backing field generation. For more information, see [Removing automatic backing field support for @ref in 3.0.0-preview9](https://github.com/aspnet/Announcements/issues/381).
@@ -537,34 +536,67 @@ When the component is rendered, the `loginDialog` field is populated with the `M
537
536
> [!IMPORTANT]
538
537
> The `loginDialog` variable is only populated after the component is rendered and its output includes the `MyLoginDialog` element. Until that point, there's nothing to reference. To manipulate components references after the component has finished rendering, use the `OnAfterRenderAsync` or `OnAfterRender` methods.
539
538
540
-
<!-- HOLD https://github.com/aspnet/AspNetCore.Docs/pull/13818
541
-
Component references provide a way to reference a component instance so that you can issue commands to that instance, such as `Show` or `Reset`.
539
+
While capturing component references use a similar syntax to [capturing element references](xref:blazor/javascript-interop#capture-references-to-elements), it isn't a [JavaScript interop](xref:blazor/javascript-interop) feature. Component references aren't passed to JavaScript code—they're only used in .NET code.
542
540
543
-
The Razor compiler automatically generates a backing field for element and component references when using [@ref](xref:mvc/views/razor#ref). In the following example, there's no need to create a `myLoginDialog` field for the `LoginDialog` component:
541
+
> [!NOTE]
542
+
> Do **not** use component references to mutate the state of child components. Instead, use normal declarative parameters to pass data to child components. Use of normal declarative parameters result in child components that rerender at the correct times automatically.
544
543
545
-
```cshtml
546
-
<LoginDialog @ref="myLoginDialog" ... />
544
+
## Invoke component methods externally to update state
547
545
548
-
@code {
549
-
private void OnSomething()
546
+
Blazor uses a `SynchronizationContext` to enforce a single logical thread of execution. A component's lifecycle methods and any event callbacks that are raised by Blazor are executed on this `SynchronizationContext`. In the event a component must be updated based on an external event, such as a timer or other notifications, use the `InvokeAsync` method, which will dispatch to Blazor's `SynchronizationContext`.
547
+
548
+
For example, consider a *notifier service* that can notify any listening component of the updated state:
549
+
550
+
```csharp
551
+
publicclassNotifierService
552
+
{
553
+
// Can be called from anywhere
554
+
publicasyncTaskUpdate(stringkey, intvalue)
550
555
{
551
-
myLoginDialog.Show();
556
+
if (Notify!=null)
557
+
{
558
+
awaitNotify.Invoke(key, value);
559
+
}
552
560
}
561
+
562
+
publiceventAction<string, int, Task> Notify;
553
563
}
554
564
```
555
565
556
-
When the component is rendered, the generated `myLoginDialog` field is populated with the `LoginDialog` component instance. You can then invoke .NET methods on the component instance.
566
+
Usage of the `NotifierService` to update a component:
557
567
558
-
In some cases, a backing field is required. For example, declare a backing field when referencing generic components. To suppress backing field generation, specify the `@ref:suppressField` parameter.
568
+
```cshtml
569
+
@page "/"
570
+
@inject NotifierService Notifier
571
+
@implements IDisposable
559
572
560
-
> [!IMPORTANT]
561
-
> The generated `myLoginDialog` variable is only populated after the component is rendered and its output includes the `LoginDialog` element. Until that point, there's nothing to reference. To manipulate components references after the component has finished rendering, use the `OnAfterRenderAsync` or `OnAfterRender` methods.
While capturing component references use a similar syntax to [capturing element references](xref:blazor/javascript-interop#capture-references-to-elements), it isn't a [JavaScript interop](xref:blazor/javascript-interop) feature. Component references aren't passed to JavaScript code—they're only used in .NET code.
575
+
@code {
576
+
private (string key, int value) lastNotification;
565
577
566
-
> [!NOTE]
567
-
> Do **not** use component references to mutate the state of child components. Instead, use normal declarative parameters to pass data to child components. Use of normal declarative parameters result in child components that rerender at the correct times automatically.
578
+
protected override void OnInitialized()
579
+
{
580
+
Notifier.Notify += OnNotify;
581
+
}
582
+
583
+
public async Task OnNotify(string key, int value)
584
+
{
585
+
await InvokeAsync(() =>
586
+
{
587
+
lastNotification = (key, value);
588
+
StateHasChanged();
589
+
});
590
+
}
591
+
592
+
public void Dispose()
593
+
{
594
+
Notifier.Notify -= OnNotify;
595
+
}
596
+
}
597
+
```
598
+
599
+
In the preceding example, `NotifierService` invokes the component's `OnNotify` method outside of Blazor's `SynchronizationContext`. `InvokeAsync` is used to switch to the correct context and queue a render.
568
600
569
601
## Use \@key to control the preservation of elements and components
570
602
@@ -1356,7 +1388,7 @@ public class CultureController : Controller
1356
1388
The following component shows an example of how to perform the initial redirection when the user selects a culture:
1357
1389
1358
1390
```cshtml
1359
-
@inject IUriHelper UriHelper
1391
+
@inject NavigationManager NavigationManager
1360
1392
1361
1393
<h3>Select your language</h3>
1362
1394
@@ -1372,12 +1404,12 @@ The following component shows an example of how to perform the initial redirecti
@@ -1397,3 +1429,21 @@ A limited set of ASP.NET Core's localization scenarios are currently supported:
1397
1429
*`IHtmlLocalizer<>`, `IViewLocalizer<>`, and Data Annotations localization are ASP.NET Core MVC scenarios and **not supported** in Blazor apps.
1398
1430
1399
1431
For more information, see <xref:fundamentals/localization>.
1432
+
1433
+
## Scalable Vector Graphics (SVG) images
1434
+
1435
+
Since Blazor renders HTML, browser-supported images, including Scalable Vector Graphics (SVG) images (*.svg*), are supported via the `<img>` tag:
1436
+
1437
+
```html
1438
+
<imgalt="Example image"src="some-image.svg" />
1439
+
```
1440
+
1441
+
Similarly, SVG images are supported in the CSS rules of a stylesheet file (*.css*):
1442
+
1443
+
```css
1444
+
.my-element {
1445
+
background-image: url("some-image.svg");
1446
+
}
1447
+
```
1448
+
1449
+
However, inline SVG markup isn't supported in all scenarios. If you place an `<svg>` tag directly into a component file (*.razor*), basic image rendering is supported but many advanced scenarios aren't yet supported. For example, `<use>` tags aren't currently respected, and `@bind` can't be used with some SVG tags. We expect to address these limitations in a future release.
Copy file name to clipboardExpand all lines: aspnetcore/blazor/dependency-injection.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ Default services are automatically added to the app's service collection.
27
27
| ------- | -------- | ----------- |
28
28
|<xref:System.Net.Http.HttpClient>| Singleton | Provides methods for sending HTTP requests and receiving HTTP responses from a resource identified by a URI. Note that this instance of `HttpClient` uses the browser for handling the HTTP traffic in the background. [HttpClient.BaseAddress](xref:System.Net.Http.HttpClient.BaseAddress) is automatically set to the base URI prefix of the app. For more information, see <xref:blazor/call-web-api>. |
29
29
|`IJSRuntime`| Singleton | Represents an instance of a JavaScript runtime where JavaScript calls are dispatched. For more information, see <xref:blazor/javascript-interop>. |
30
-
|`IUriHelper`| Singleton | Contains helpers for working with URIs and navigation state. For more information, see [URI and navigation state helpers](xref:blazor/routing#uri-and-navigation-state-helpers). |
30
+
|`NavigationManager`| Singleton | Contains helpers for working with URIs and navigation state. For more information, see [URI and navigation state helpers](xref:blazor/routing#uri-and-navigation-state-helpers). |
31
31
32
32
A custom service provider doesn't automatically provide the default services listed in the table. If you use a custom service provider and require any of the services shown in the table, add the required services to the new service provider.
0 commit comments