diff --git a/site/Site/Pages/Documentation/Diagram/Behaviors.razor b/site/Site/Pages/Documentation/Diagram/Behaviors.razor index 4f3785ad..ff9a5f7d 100644 --- a/site/Site/Pages/Documentation/Diagram/Behaviors.razor +++ b/site/Site/Pages/Documentation/Diagram/Behaviors.razor @@ -120,11 +120,10 @@ You can use the following ways to add different behaviors to the diagram.

Scroll Behavior

-

To scroll the diagram using the mouse wheel you can register the Scroll Behavior.

+

To scroll the diagram using the mouse wheel use ScrollBehavior.


-Diagram.UnregisterBehavior<WheelBehavior>();
-Diagram.RegisterBehavior(new ScrollBehavior(Diagram));
+_diagram.BehaviorOptions.DiagramWheelBehavior = _diagram.GetBehavior<ScrollBehavior>();
 
diff --git a/src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs b/src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs index a970780d..815e29be 100644 --- a/src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs +++ b/src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Blazor.Diagrams.Core.Behaviors; using Blazor.Diagrams.Core.Geometry; using Blazor.Diagrams.Extensions; using Microsoft.AspNetCore.Components; @@ -64,7 +65,10 @@ protected override async Task OnAfterRenderAsync(bool firstRender) { BlazorDiagram.SetContainer(await JSRuntime.GetBoundingClientRect(elementReference)); await JSRuntime.ObserveResizes(elementReference, _reference!); - await JSRuntime.AddDefaultPreventingHandler(elementReference); + if (BlazorDiagram.GetBehavior() != null) + { + await JSRuntime.AddDefaultPreventingForWheelHandler(elementReference); + } } } @@ -102,7 +106,7 @@ private void OnKeyDown(KeyboardEventArgs e) BlazorDiagram.TriggerKeyDown(e.ToCore()); } - private async void OnWheel(WheelEventArgs e) + private void OnWheel(WheelEventArgs e) { BlazorDiagram.TriggerWheel(e.ToCore()); } diff --git a/src/Blazor.Diagrams/Extensions/JSRuntimeExtensions.cs b/src/Blazor.Diagrams/Extensions/JSRuntimeExtensions.cs index c1188622..5509f742 100644 --- a/src/Blazor.Diagrams/Extensions/JSRuntimeExtensions.cs +++ b/src/Blazor.Diagrams/Extensions/JSRuntimeExtensions.cs @@ -31,7 +31,7 @@ public static async Task UnobserveResizes(this IJSRuntime jsRuntime, ElementRefe await jsRuntime.InvokeVoidAsync("ZBlazorDiagrams.unobserve", element, element.Id); } - public static async Task AddDefaultPreventingHandler(this IJSRuntime jsRuntime, ElementReference element) + public static async Task AddDefaultPreventingForWheelHandler(this IJSRuntime jsRuntime, ElementReference element) { await jsRuntime.InvokeVoidAsync("ZBlazorDiagrams.addDefaultPreventingHandler", element, "wheel"); }