BQuery is a Blazor helper library for JavaScript interop (inspired by jQuery).
It provides:
- Element DOM helpers (
Attr, class/style helpers) - Element measurement and position APIs
- Viewport measurement APIs
- Window event binding with .NET callbacks
- Element drag helpers
| BQuery | .NET |
|---|---|
| 4.x | .NET 8.0 / .NET 10.0 |
| 3.x | .NET 6 |
| 2.x | .NET 5 |
If you're upgrading from 3.x, please review the following API and platform changes:
- Target frameworks changed: BQuery 4.x targets .NET 8.0 and .NET 10.0 only. .NET 6 is no longer supported.
- Startup extensions removed: the old
AspNetExtensionspackage surface (for exampleUseBQuery(...)) was removed. Use DI registration withAddBQuery()and load the static asset from_content/BQuery/dist/.... - Resize callback payload changed: resize handlers now use
ResizeEventArgs(with named properties like width/height) instead of positional payload patterns.
- Update your app TFM to .NET 8+.
- Replace legacy startup extension usage with
builder.Services.AddBQuery();. - Ensure your host page (or startup script flow) loads
_content/BQuery/dist/bQuery.min.js. - Update resize event handlers to
OnResizeAsync(ResizeEventArgs args)/OnResize(ResizeEventArgs args).
dotnet add package BQuerybuilder.Services.AddBQuery();Note
If using Interactive Auto render mode, the service needs to be registered in both the App and App.Client simultaneously.
Add this script to your host page:
<script src="_content/BQuery/dist/bQuery.min.js"></script>The repository samples use the UMD build (bQuery.min.js).
<script src="_content/BQuery/dist/bQuery.min.js"></script>
<script src="_framework/blazor.webassembly.js"></script><script src="_content/BQuery/dist/bQuery.min.js"></script>
<script src="_framework/blazor.server.js"></script><script src="_content/BQuery/dist/bQuery.min.js"></script>
<script src="@Assets["_framework/blazor.web.js"]"></script>@inject Bq bq
@implements IAsyncDisposable
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
{
return;
}
await bq.AddWindowEventListener<ResizeEventArgs>(WindowEvent.OnResize, OnResizeAsync);
}
private Task OnResizeAsync(ResizeEventArgs args)
{
Console.WriteLine($"Viewport: {args.Width} x {args.Height}");
return Task.CompletedTask;
}
public async ValueTask DisposeAsync()
{
// Remove only this component's callback. Other subscribers share the scope.
await bq.RemoveWindowEventListener<ResizeEventArgs>(WindowEvent.OnResize, OnResizeAsync);
}
}var width = await bq.Viewport.GetWidthAsync();
var height = await bq.Viewport.GetHeightAsync();
var scrollTop = await bq.Viewport.GetScrollTopAsync();var size = await element.GetWidthAndHeightAsync();
var docPos = await element.GetPositionInDocAsync();
await element.AddCls("is-active");
await element.Css("display", "none");
await element.RemoveCls("is-active");await bq.Drag.BindDragAsync(dialog, new DragOptions
{
InViewport = true,
DragElement = dialogHeader
});
await bq.Drag.ResetDragPositionAsync(dialog, new DragOptions
{
DragElement = dialogHeader
});
await bq.Drag.RemoveDragAsync(dialog, new DragOptions
{
DragElement = dialogHeader
});var ua1 = await bq.GetUserAgentAsync();
var ua2 = await jsRuntime.GetUserAgentAsync(); // IJSRuntime extensionSample/BQuery.Sample.WasmSample/BQuery.Sample.ServerSample/BQuery.Sample.Client— shared WebAssembly bootstrap for Wasm and AutoSample/BQuery.Sample.CommonSample/BQuery.Sample.Auto
The three .NET 10 hosts share the same English interactive laboratory. Server (5301), Wasm (5302), and Auto (5303) use Interactive Server, WebAssembly, and Auto respectively. See Sample guide and coverage for startup commands, routes, lifecycle notes and verification.
MIT