![]() |
|
Blazor 0.4.0 experimental release now available - Printable Version +- Sick Gaming (https://sickgaming.net) +-- Forum: Programming (https://sickgaming.net/forum-76.html) +--- Forum: C#, Visual Basic & .NET (https://sickgaming.net/forum-79.html) +--- Thread: Blazor 0.4.0 experimental release now available (/thread-85126.html) |
Blazor 0.4.0 experimental release now available - xSicKxBot - 06-08-2018 Blazor 0.4.0 experimental release now available Blazor 0.4.0 is now available! This release includes important bug fixes and several new feature enhancements. New features in Blazor 0.4.0 (details below):
A full list of the changes in this release can be found in the Blazor 0.4.0 release notes. Get Blazor 0.4.0 To get setup with Blazor 0.4.0:
To install the Blazor templates on the command-line: Code: dotnet new -i Microsoft.AspNetCore.Blazor.TemplatesYou can find getting started instructions, docs, and tutorials for Blazor at https://blazor.net. Upgrade an existing project to Blazor 0.4.0 To upgrade an existing Blazor project from 0.3.0 to 0.4.0:
Your upgraded Blazor project file should look like this: Code: <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> <RunCommand>dotnet</RunCommand> <RunArguments>blazor serve</RunArguments> <LangVersion>7.3</LangVersion> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="0.4.0" /> <PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="0.4.0" /> <DotNetCliToolReference Include="Microsoft.AspNetCore.Blazor.Cli" Version="0.4.0" /> </ItemGroup> </Project>This release adds payloads for the following event types: Event arguments | Events UIMouseEventArgs | onmouseover, onmouseout, onmousemove, onmousedown, onmouseup, oncontextmenu UIDragEventArgs | ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop UIPointerEventArgs | gotpointercapture, lostpointercapture, pointercancel, pointerdown, pointerenter, pointerleave, pointermove, pointerout, pointerover, pointerup UITouchEventArgs | ontouchcancel, ontouchend, ontouchmove, ontouchstart, ontouchenter, ontouchleave UIWheelEventArgs | onwheel, onmousewheel UIKeyboardEventArgs | onkeydown, onkeyup UIKeyboardEventArgs | onkeydown, onkeyup, onkeypress UIProgressEventArgs | onloadstart, ontimeout, onabort, onload, onloadend, onprogress, onerror Thank you to Gutemberg Ribeiro (galvesribeiro) for this contribution! If you haven’t checked out Gutemberg’s handy collection of Blazor extensions they are definitely worth a look. Use camelCase for JSON handling The Blazor JSON helpers and utilities now use camelCase by default. .NET objects serialized to JSON are serialized using camelCase for the member names. On deserialization a case-insensitive match is used. The casing of dictionary keys is preserved. Automatic import of core for Blazor namespaces in Razor Blazor now automatically imports the Microsoft.AspNetCore.Blazor and Microsoft.AspNetCore.Blazor.Components namespaces in Razor files, so you don’t need to add Code: @usingSend and receive binary HTTP content using HttpClient You can now use Code: HttpClientBind to numeric types Binding now works with numeric types: Code: longCode: floatCode: doubleCode: decimalTemplates run on IIS Express by default with autobuild enabled The Blazor project templates are now setup to run on IIS Express by default, while still preserving autobuild support. JavaScript interop improvements Call async JavaScript functions from .NET With Blazor 0.4.0 you can now call and await registered JavaScript async functions like you would an async .NET method using the new Code: RegisteredFunction.InvokeAsyncCode: Blazor.registerFunction('BlazorLib1.DelayedText', function (text) { // Wait 1 sec and then return the specified text return new Promise((resolve, reject) => { setTimeout(() => { resolve(text); }, 1000); });
});You then invoke this async JavaScript function using Code: InvokeAsyncCode: public static class ExampleJSInterop
{ public static Task<string> DelayedText(string text) { return RegisteredFunction.InvokeAsync<string>("BlazorLib1.DelayedText", text); }
}Now you can await the async JavaScript function like you would any normal C# async method: Code: var text = await ExampleJSInterop.DelayedText("See ya in 1 sec!");Blazor 0.4.0 makes it easy to call sync and async .NET methods from JavaScript. For example, you might call back into .NET when a JavaScript callback is triggered. While calling into .NET from JavaScript was possible with earlier Blazor releases the pattern was low-level and difficult to use. Blazor 0.4.0 provides simpler pattern with the new Code: Blazor.invokeDotNetMethodCode: Blazor.invokeDotNetMethodAsyncTo invoke a .NET method from JavaScript the target .NET method must meet the following criteria:
For example, let’s say you wanted to invoke the following .NET method when a timeout is triggered: Code: namespace Alerts
{ public class Timeout { public static void TimeoutCallback() { Console.WriteLine('Timeout triggered!'); } }
}You can call this .NET method from JavaScript using Code: Blazor.invokeDotNetMethodCode: Blazor.invokeDotNetMethod({ type: { assembly: 'MyTimeoutAssembly', name: 'Alerts.Timeout' }, method: { name: 'TimeoutCallback' }
})When invoking an async .NET method from JavaScript if the .NET method returns a task, then the JavaScript Code: invokeDotNetMethodAsyncCode: PromiseSummary We hope you enjoy this latest preview of Blazor. Your feedback is especially important to us during this experimental phase for Blazor. If you run into issues or have questions while trying out Blazor please file issues on GitHub. You can also chat with us and the Blazor community on Gitter if you get stuck or to share how Blazor is working for you. After you’ve tried out Blazor for a while please also let us know what you think by taking our in-product survey. Just click the survey link shown on the app home page when running one of the Blazor project templates: Thanks for trying out Blazor! |