Take Screenshot and Download with Blazor WebAssembly
Get link
Facebook
X
Pinterest
Email
Other Apps
-
This blog will show you how to take a screenshot with Blazor WebAssembly. There is currently no way to take a screenshot in Blazor. So, in this blog, I'll use the Javascript library html2canvas to capture and download the screenshot.
The code below is an index.razor code. In the source code. To use Javascript functions, IJSRuntime is injected. To collect the message, I've added a textbox. This message will be captured in the screenshot. Two new buttons have been added. The first is to take a screenshot, and the second is to download the screenshot. Two methods for taking and downloading screenshots have been added to the @code area. The Javascript methods Takeshot and DownloadImg do not return any values, So I use the InvokeVoidAsync method to call them.
The code for the index.html file is shown below. Inside the <body> tag, I've added the html2canvas.min.js cdn and SampleJavaScript.js script tags. As a result, the html2canvas javascript files and SampleJavaScript.js will be loaded.
The output of the above code is shown below. When the user clicks the Take button, the message is captured, and when the user clicks the Download button, the image is downloaded.
This blog is going to illustrate how to implement Entity Framework (EF) Core with SQL Server LocalDB. The Entity Framework Core enables access to data from the database. This allows developers to avoid having to write most of the data access code. And the SQL Server LocalDB works similarly to the SQL SERVER with few features. You can get the LocalDB when you install visual studio or visual studio express. You can find the .mdf and _log.ldf files in the C:/Users/{user} directory. Let see how to create a SQL Server LocalDB and implement Entity Framework Core Step 1: The first step is to add a connection. In the menu -> click Tools and select Connect to Database It will display the Add Connection window. Enter (localdb)\mssqllocaldb in the server name textbox. Then in the Select or enter a database, select master and click ok Now in the server explorer, you can find the master DB containing Tables, Views, Stored...
Developers need to manage the resources used in the application. They need to release unmanaged resources that will help prevent memory leaks. The Blazor provides two implementations for releasing the component. IDisposable and IAsyncDisposable IDisposable The following is a small example of the code to illustrate the disposal of components in Blazor. The first step is to implement the IDisposable interface using the @implements directive. The Dispose() method is then used to release the memory. @page "/sample" @implements IDisposable @code { Movie movieObj; private void CollectValues() { movieObj = new Movie(); ... ... ... } public void Dispose() { movieObj?.Dispose(); } } If only one object requires disposal, you can use the lambda expression. public void Dispose() => movieObj?.Dispose(); IAsyncDisposable You can use IAsyncDisposable.DisposeAsync for asynchronous disposal. The follo...
Using Query Strings for Request Culture and Simplifying Localization with IStringLocalizer Interface Let’s see how to implement Localization in ASP.NET Core MVC. In the first example, I am going to use the IStringLocalizer Interface in the controller to implement Localization. Additionally, when the user passes the desired language through the query string, it will display content in that language. First, let’s configure the settings in the program.cs file. builder.Services.AddLocalization(options => options.ResourcesPath = "Resources"); The AddLocalization method adds the localization service to the service container. I have added the supported cultures here. I have added two cultures: en for English and nl for Dutch. In the RequestCultureProviders , I have included QueryStringRequestCultureProvider() . This allows the system to determine the culture information from the query string. UseRequestLocalization initializes a RequestLocalizationOptions o...
Comments
Post a Comment